Hi,
I want to different color of different length in lines. first 3 char in different color, the next 4 char in green color etc…
forexample,
This is a coloring example
Thi = red color
s is = blue color
a coloring = orange color
Can someone guide me?
i am not getting the colors on each line, are there any methods available to get the line number?
textEditor.setText("This is first line\
This is second line
This is third line");
StyledDocument doc = textEditor.getStyledDocument();
Style styleRed = textEditor.addStyle("Red", null);
StyleConstants.setForeground(styleRed, Color.red);
Style styleGreen = textEditor.addStyle("Green", null);
StyleConstants.setForeground(styleGreen, Color.green);
lines = textEditor.getText().split("\
");
for(int i=0; i<lines.length; i++)
{
doc.setCharacterAttributes(0, 4, styleRed, true);
doc.setCharacterAttributes(4, 6, styleGreen, true);
}