0

I have a java code which requires highlighting different words in a text area using different colors. I managed to get the default blue color highlighting by

JTextArea textArea=new JTextArea();
textArea.setText('some text in textArea');
String tx=textArea.getText();
Highlighter h=textArea.getHighlighter();
String string_to_highlight=  "text";
int pos=tx.indexOf(string_to_highlight,0);
h.addHighlight(pos, pos+string_to_highlight.length(), DefaultHighliter.DefaultPainter);

Could anyone please help me to get other colors like Red, Yellow, etc. Thanks.

Nipuna Dilhara
  • 424
  • 2
  • 6
  • 18

0 Answers0