I have a file which i will read it line by line. Split each line into words by using the split method and color the words based on their positions (first 4 chars of each line etc) and also based on the words. Different color should be applied to different words like below. I want to know which class is useful, i looked into highlighter. Any suggestions, with example would be very helpful
String text = textArea.getText();
String newLine = "\n";
String spaceDelim = "[ ]+";
String[] tokens;
String lines = text.split(newLine);
for(String line : lines) {
tokens = line.split(spaceDelim);
tokens[1] //should be in redColor
tokens[2] //should be in greenColor
tokens[3] tokens[4] //should in blueColor
}
If you want to have different text literals to have different colours, you must read about How to use Editor Pane or TextPane. This will help you in that.
A sample program :
And here is the output of this code :