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
Asked
Active
Viewed 78 times
1
-
you need to use separate instances to achieve that – Iłya Bursov Apr 04 '17 at 20:08
-
A `JTextPane` makes use of a `StyledDocument`, I sugget having a look at [How to Use Editor Panes and Text Panes](https://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html) as a primer – MadProgrammer Apr 04 '17 at 20:10
-
[For example](http://stackoverflow.com/questions/22184448/surrounding-jtextpane-with-images/22185053#22185053) – MadProgrammer Apr 04 '17 at 20:12
1 Answers
1
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?