1

I have a JTextPane that contains a predefined text block. I have a separate thread that highlights certain lines of the text and periodically removes the highlight.

I am highlighting using: text.getHighLighter().addHighligh(start,end,highlighter) and removing using text.getHighLighter().removeAllHighLights() and i call text.revalidate() after it.

Sometimes the highlights are not removed?!

Can someone see a potential issue that I am having?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Josh
  • 818
  • 2
  • 16
  • 27
  • please what's wrong with [Java Default Highlighter](http://stackoverflow.com/questions/9078275/java-default-highlighter) – mKorbel Feb 24 '12 at 11:54
  • please show an sscce that demonstrates the problem (btw: revalidate shouldn't be needed) – kleopatra Feb 25 '12 at 13:44

1 Answers1

0

Are you running your code to highlight/remove in the EDT?

As in

SwingUtilities.invokeLater(new Runnable(){
    @Override
    public void run(){
        text.getHighLighter().removeAllHighLights();
    }
});
Marcelo
  • 4,580
  • 7
  • 29
  • 46