The deriveFont(float size)
method just makes the Font
plain without changing its size.
JButton prevButton = new JButton("Previous");
prevButton.setFont(prevButton.getFont().deriveFont(90));
If I use deriveFont(int style, float size) like in the following example it works as intended.
JButton prevButton = new JButton("Previous");
prevButton.setFont(prevButton.getFont().deriveFont(Font.BOLD, 90));
Can someone explain this behaviour?
Check the variable arguments of all deriveFont
overloads. When you deriveFont(90)
, (someone could say it is kind ambiguous) you are changing the style of the font and not the size. The method is deriveFont(int style)
, where accepted style
values are Font.BOLD
,Font.ITALIC
and Font.PLAIN
.
In the other hand, another overload of this method is deriveFont(float size)
. Note the float
. In order to make this work you should deriveFont((float) 90)
or deriveFont(90f)
as @camickr pointed in comments. Casting the int
to float
will make it clear you want to change the size.