Forums Register Login

word wrap styled text area?

+Pie Number of slices to send: Send
I need to display read-only text such that it wraps and contains style.

If I use JTextArea, set columns to something and flag the appropriate properties to wrap, I get exactly what I want with the exception of the style. For example,

The quick brown fox
jumped over the lazy
dog.

If I use JEditorPane to style the text (for example, make the word "brown" bold) by setting the content type to "text/html" and setting the text to the appropriate html, I get the style (i.e., color) that I want but my text no longer wraps. For example,

The quick brown fox jumped over the lazy dog.

My text area ends up being added to a JPanel with other things (using GridBadLayout) and this JPanel is placed in a scroll pane.

Does anyone have any suggestions for how I can get both word wrapping and style?

Thanks!
+Pie Number of slices to send: Send
For word wrap, you need both:

myEditorPane.setLineWrap(true);
myEditorPane.setWrapStyleWord(true);

You might try adding the JEditorPane to the JScrollPane and adding that to your layout without the intermediate panel.

Good luck,
Mike
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2990 times.
Similar Threads
Help with weird IO problem
Replacing the the last character of the given String
Multithreading: Two errors with education.oracle.com sample exam question
MS word
How do we do a Text Wrap
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:27:47.