Hi Mr.Dennis,
Yes u can achieve this with TextPane. U have to get the textpanes StyledDocument and use SimpleAttributeSet class
to achieve this functionality. I have furnished few lines of
code which will act as a guideline to solve ur problem.
JTextPane textpane=new JTextPane();
StyledDocument doc=textpane.getStyledDocument();
SimpleAttributeSet set=new SimpleAttributeSet();
javax.swing.text.StyleConstants.setForeground(set,new Color(0,35,3));
int startposition=5;
int lengthtobemarkedwith=6;
doc.setCharacterAttributes(startposition,lengthtobemarkedwith,set,false);
In this way u can bring about a different text color for a specied range of text in a textpane. Hope this would be useful
to u. All the best.
Regards,
Premila
Originally posted by Dennis Spathis:
Hi all,
I need to develop a text editor with the following two
features:
1. Quoted text should appear in a colour different from
that of normal text.
2. Selected words should be recognized by the editor as
key words and should appear in a colour different from
that of normal or quoted text.
This is new territory for me. I know that I should use a
JTextPane, but after that I'm not sure. I was thinking of
implement a CaretListener and/or a DocumentListener to implement
the aforementioned features. Am I on the right track? Would
implementing a custom EditorKit be a better strategy?
Thanks,
Dennis