javaswingfontsjtextcomponent

Multiple fonts and styles in JTextComponent


I am looking for a way to print content in JTextComponent's text with multiple fonts and styles. For example: first Title with bigger font and then some custom text in different style in one component


Solution

  • You can use a JTextPane for this. You can control font, color, bold, size etc.

    Read the section from the Swing tutorial on Text Component Features for more information and working examples.

    For a another simple example to get you started check out: Is there a way to filter / search for content in a HTMLEditorKit?