user6248420
user6248420

Reputation:

JTextArea I want to make my part of text bold or cursive

I have a problem with JTextArea. I dont know how can I change part of my text in JTextArea to be bold or to be cursive. Anyone?

Upvotes: 0

Views: 880

Answers (1)

K139
K139

Reputation: 3679

Use Simple Attributes to change the text font and color. like

SimpleAttributeSet attrSet= new SimpleAttributeSet();
StyleConstants.setFontFamily(attrSet, "Courier New Italic");
StyleConstants.setForeground(attrSet, Color.BLUE);

textArea.getDocument().insertString(0, "Your text is here", attrSet);

and alternatively, you will get much more advantage and flexibility, if you use editor or text panes.

Upvotes: 1

Related Questions