[Advanced-java] Syntax Highlighting - using Swing - JTextPane
Florian Roth
rothflorian at gmx.de
Mon Mar 3 10:13:06 2003
Hi
The way I did synatax highlighting was overwriting the insertString() method
DefaultStyledDocument class. Then I set an own EditorKit whose
createDefaultDocument() method was returning an instance of my document
class.
for example like this:
JTextPane pane = new JTextPane();
pane.setEditorKit(new StyledEditorKit(){
public Document createDefaultDocument(){
//return the document
}
});
In the documents insertString(String str, in offset, AttributeSet a) method,
you can check the input and replace the AttributeSet by an own one
containing your properties. Hava a look in the docu for
javax.swing.text.StyleConstants.
Greets
Florian