user2297416
user2297416

Reputation: 11

Set a string to bold in JTextArea?

I don't want to set the entire text area to bold but just a selected single line. How would go about doing that?

Upvotes: 1

Views: 4857

Answers (3)

Oswald
Oswald

Reputation: 31647

According to the documentation of JTextArea,

A JTextArea is a multi-line area that displays plain text.

plain text, in this sense, means every character is formated the same way. There is no way to format some characters differently than other characters.

Upvotes: 1

CodeBlue
CodeBlue

Reputation: 15389

There is no way to do it with JTextArea. You can achieve this with JEditorPane.

JEditorPane editorPane = new JEditorPane();
editorPane.setContentType("text/html");
editorPane.setText("<b>This text is bold</b>"); 

Upvotes: 2

Related Questions