Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

word wrap styled text area?

 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Mike Rainville
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!