Is there a way, to highlight or change the color of a string that gets added from a String[] to a JTextArea? Currently I'm using the DefaultHighlighter with the addHighlighter(from, to, highlighter) method, but that does not work the way ' want it to. The String[] comes from a list that records key imput, and ' want every singlecharacter string to be highlighted to colored.
Example what the JTextArea looks like: A B C D E F G [SPACE] H I J K L [ENTER].
By the way, I add one string at a time to the textArea with a for loop like that:
for(int cnt = 0; cnt <= strings.length; cnt++){
if(strings[cnt].length() != 1){
text.append("[" + strings[cnt] + "] ");
}
else{
text.append(strings[cnt]);
//tryed to do it like that, but obviously did not work the way it wanted it to
// text.getHighlighter().addHighlight(cnt, cnt + 1, highlightPainter); } }