Search code examples
javaswingfontsjtextarea

Decorating JTextArea


I'm appending text to a text area using .append method, I've been trying to make the text which gets appended bold and also change colour.

Is this not possible with JTextArea area, I only want one line to be bold and a different colour and the rest the default font.

Do I need to use something other than JTextArea?


Solution

  • For having different lines/words/characters with different Font or colour setting you need either JTextPane or JEditorPane, How to Use Editor Panes and Text Panes.

    In JTextArea, the whole document is bound to have one single setting in terms of FONT or COLOUR.

    Hope this might help.

    Regards