Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Highlighting Text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Highlighting Text" Watch "Highlighting Text" New topic
Author

Highlighting Text

Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Hi. I currently use a JTextArea to display my text and I can highlight certain portions of it using a the Highlighter class. However, when I switch to a JEditorPane and display HTML I run into some problems.

When I highlight the text, I do it based on the index of the characters (for example, highlight characters 10-20). When I switched to the JEditorPane, these highlights do not highlight the same places any more (even when I don't have any HTML being displayed). Can someone explain to me why this is happening and how I might go about highlighting the correct indices in the JEditorPane?

Thank you.
Jeff Storey
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
It's kind of hard to answer without more information. You might post some code.

I'm kind of confused why you mention HTML here. JEditorPane can display HTML (using the HTMLEditorKit) but can also display other kinds of formatted text. If you don't need to actually mess with HTML or RTF or something like that, you may want to use a JTextPane instead. (JTextPane happens to be a subclass of JEditorPane.)


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Highlighting Text