Sachin Kumar
Sachin Kumar

Reputation: 781

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.

Upvotes: 0

Views: 663

Answers (3)

StanislavL
StanislavL

Reputation: 57421

Cast it to styled document

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

Upvotes: 3

Joop Eggen
Joop Eggen

Reputation: 109613

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

Upvotes: 1

GerritCap
GerritCap

Reputation: 1626

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

Upvotes: 1

Related Questions