• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Multicolored JTextPane/ JEditorPane/ JTextArea output

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiya,
I'm making a program that utilizes a frequently updated multi lined text component, which is currently not in color. And I'd like to make it in color. I've tried to read stuff on JEditorPane and using setContentType() and all that, and a little JTextPane stuff, but all of it makes my head spin. Any help would be appreciated.

P.S. The JTextArea I'm using uses a lot of append()s.
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could check out javax.swing.text.Highlighter, particularly javax.swing.text.DefaultHighlighter and javax.swing.text.DefaultHighlighter.DefaultHighlightPainter:

This code will paint the first 15 characters of a JTextComponent called text in read.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jack Conger:
I'm making a program that utilizes a frequently updated multi lined text component, which is currently not in color. And I'd like to make it in color. I've tried to read stuff on JEditorPane and using setContentType() and all that, and a little JTextPane stuff, but all of it makes my head spin. Any help would be appreciated.

P.S. The JTextArea I'm using uses a lot of append()s.



It's possible to use highlighters as Mr. Prime suggests, but this
is what JTextPane was made for. It need not make your head spin.
For instance, here's a simple example that appends colored text.

disclaimer: I wrote that example. That site took it from my book.
It's from chapter 22, which is a hundred-page introduction to
JTextPane and AttributeSets. You can read part of it at
Google Books (click on "more �" under "Contents", then on
"Styled Text Panes") but some pages are missing. My publisher
would prefer you purchased the book.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic