Originally posted by danish shaikh:
I m creating n Text Editor using JEditorPane().
I want to change the color of the text as i type ne new thing in editorpane.
For that i have used the folloeing code:--
set=new SimpleAttributeSet();
StyleConstants.setForeground(set, Color.RED);
StyleConstants.setUnderline(set, true);
StyledEditorKit.StyledTextAction.setCharacterAttributes(editor,set,true);
Well you've got a couple of problems here. The one the compiler is complaining about is that setCharacterAttributes() is not a static method in StyledEditorKit.StyledTextAction. I guess that's why this
thread was moved to the beginner forum.
In addition, StyledEditorKit.StyledTextAction is an abstract class and it presumes that the JEditorPane's EditorKit is a StyledEditorKit. If your EditorKit isn't a StyledEditorKit (or a subclass, such as HTMLEditorKit) then StyledEditorKit.StyledTextAction.setCharacterAttributes() will throw a IllegalArgumentException.
On the other hand, if you know that it
is a StyledEditorKit, then you don't need to use StyledTextAction. You could call getInputAttributes().addAttributes(set) directly on your StyledEditorKit.
btw, if you would use a JTextPane instead of a JEditorPane things might be easier. Not only would that guarantee that you were using a StyledEditorKit, but JTextPane defines setCharacterAttributes() and getInputAttributes() methods that you can use directly without messing with EditorKits.
Is there a reason you need to use JEditorPane instead of JTextPane?
[ January 26, 2007: Message edited by: Brian Cole ]