How to set text font in JTextpane using double value in Java Swing

Hi, I am trying to create a Java Swing application where the user will be able to set the desired font size of the text in jtextpane. I use "StyleConstants.setFontSize (attr, int);". This only works for an integer value, but when the user gives a double value of Eg (8.5), the above command fails because it accepts only an integer value, not a double value. So how do I solve this? Is there any command that takes a double value?

Thank you in advance

+4
source share
2 answers

You can try through HTML / CSS:

JTextPane textPane = new JTextPane(); textPane.setContentType("text/html"); textPane.setText("<span style='font-size: 8.5pt'>Hey there!</span>"); 
+1
source

The following rotation components support HTML formatting: buttons, menu items, labels, tool tips, and tabbed panels. To use formatting, you must place a tag at the beginning of the text (closing it at the end is optional.) For example:

 <html><font size="8.5pt">Two</font> 
0
source

Source: https://habr.com/ru/post/1445771/


All Articles