• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

word wrap styled text area?  RSS feed

 
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!
 
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
 
money grubbing section goes here:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!