Java wrap text around image - java

How to wrap text around an image in Java? Or how to accomplish CSS float in Java?
I am loading a HTML text with some image tags into JTextPane component.
Example:
text text text text <img src="image.ext"> text text text
Example2: http://www.bbc.co.uk/news/world-us-canada-11882019 (text left, image right something similar)
And i need the image to be wrapped with a text.
Tried using css... float: right; (Java doesn't support that feature.. need it..)
Tried all image alignments(left, right etc.) (no luck..)
P.S. PHP programmer..

The Swing tutorial on Using Text Components, shows how to use a JEditorPane to display HTML with an image.

I've implemented something like this (text flow around images and tables) for SoftChalk project (you can see the trial from http://softchalk.com/) but it's not trivial. It required a lot of changes and took significant time to implement and embed this in HTMLEditorKit extension.
I had to extend a lot of views (BlockView extension and completly change layout rows algorithms in all the possible containers - BODY, DIVs, Table cells, list items etc.

Related

How to save and open jtextpane content to/from an external file which contains Bold,Italics,Underline text, images and other styled content?

I am developing a Wordpad application using Java Swing.
I am using JTextPane component. I have added the code for Bold, Italics, Underline. I am adding the code to insert images in all the formats.
My expected scenario: I want to save the document with all these styled content with the extension '.doc' (or)'.docx'. And I want to read and open the document which contains these types of styled content like Bold, Italic, underline text and images, bullet points etc..
I don't think it can be done with HTMLEditorKit().
Can anyone help with the sample code for saving and reading these styled contents to/from external file?
Thanks in advance.

Multiple fonts and styles in JTextComponent

I am looking for a way to print content in JTextComponent's text with multiple fonts and styles.
For example: first Title with bigger font and then some custom text in different style in one component
You can use a JTextPane for this. You can control font, color, bold, size etc.
Read the section from the Swing tutorial on Text Component Features for more information and working examples.
For a another simple example to get you started check out: Is there a way to filter / search for content in a HTMLEditorKit?

Java GUI with scrolling text and images

How do I create a GUI with a scrolling text area and underneath small paragraphs of text there are corresponding images?
I am currently using a JTextArea with a scroll-bar to display the text and it works great, but I want to display the corresponding images underneath each small paragraph of text.
You can use javax.swing.JTextPane
Check TextSamplerDemo
You can find plenty of examples here:
http://www.java2s.com/Code/Java/Swing-JFC/TextPaneSample.htm
The easiest way to do this, would be to use JEditorPane with HTMLEditorKitYou can use HTML text formnatting including graphics, just like a webpage.

Replacing smiles with images in Swing text area

I am designing a chat system..i am making use of JText area to display chat, and JTextField to enter text.
My question is how to recognize smiley's like ":)" and replace it by corresponding image
on text area? i found no method which will append image on text area..Please help.
http://java-sl.com/tip_autoreplace_smiles.html
You'll have to use a read-only JEditorPane to display HTML instead of a JTextArea in that case.
JTextArea was made to display only multiple rows of text, but correct me if I'm wrong. To display Images you could use the JEditorPane control that will allow you to use html, with simple <img /> tags which will point to a image.
Regarding how to recognize smileys you could create a file / list of common patterns that you would like to support and then simple check if the text contains the pattern with the .contains , or even Regular Expressions.
Update
And with the JEditorPane you will also be to do addition things like say scan for emails or links and automatically convert them so the user can click them, always a nice feature to have.

Formatting text with HTML in a JEditorPane?

I am trying to make a simple email client in Java Swing.
I want to allow users to format their email in any way they want, like making some parts of the text bold, other parts italic, etc. In other words, I am trying to make a WYSIWYG editor. The formatting is done in HTML. I am using JEditorPane to display the text.
I have tried adding tags myself to the text directly by using setText and getText methods of JEditorPane. I could make it work for basic formatting, but it is quite difficult to handle complex formatting. (trying to remove tags from multi-tagged elements, for example)
Is there an easier way to accomplish this? I have looked at HTMLEditorKit but it seems like it does not support adding tags to and/or replacing a specific string.
Thanks in advance.
The HTMLEditorKit comes with some default Actions that allow you to do some basic styling of the text with the click of a menu item (or button). Take a look at the example in the section from the Swing tutorial on Text Component Features.

Categories

Resources