1

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

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
user2297416
  • 11
  • 1
  • 3

3 Answers3

3

I suggest using a JTextPane instead as there are example solutions for it: http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html http://www.java2s.com/Code/Java/Swing-JFC/JTextPaneStylesExample6.htm

2

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>"); 
CodeBlue
  • 14,631
  • 33
  • 94
  • 132
1

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.

Oswald
  • 31,254
  • 3
  • 43
  • 68