This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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?
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.)