Search code examples
javaswingjeditorpane

Text formatting in JEditorPane


I need to change the style(i.e font,color and other attributes) of a particular word or line.
I have tried this with JTextPane as:

textPane.getStyledDocument().setCharacterAttributes(start,length,myTextStyle,false);

Is there any way to do the same thing with JEditorPane.
How can i format a word in JEditorPane.


Solution

  • Cast it to styled document

    ((StyledDocument)editorPane.getDocument()).setCharacterAttributes(start,length,myTextStyle,false);