3

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..

1
  • 3
    Don't write it "JAVA", it makes us go all Dr David Banner. Commented Nov 30, 2010 at 20:43

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer but these images are in separate lines. Text is not wraping around them
@Brudas, The text and image are are the same line for me. Yes the image height is taller and there is only one line of text for the image, but it is on the same line.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.