Question

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.

Was it helpful?

Solution

Cast it to styled document

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

OTHER TIPS

You can use HTMl or RTF text to format text within a JEditorPane.

There is a good explanation on how to do this @ http://docs.oracle.com/javase/tutorial/uiswing/components/text.html

Mind, the naming, "JEditorPane" is misleading; JTextPane is a subclass of JEditorPane. So if you want to make your own styled editor, use JTextPane.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top