Are there any built-in methods in Java to increase Font size?
+6
A:
The Font
class allows you to specify font size.
So, to create a font you do something like this:
Font f = new Font("serif", Font.PLAIN, fontSize);
The fontSize
parameter will determine the size of your Font
.
You can't actually change the size of an existing Font object. The best way to achieve a similar effect is to use the deriveFont(size)
method to create a new almost identical Font
that is a different size.
Font biggerFont = existingFont.deriveFont(bigNumber);
jjnguy
2009-06-25 13:24:33
+3
A:
You can derive a new Font with a different size by using the following:
Font original = // some font
Font bigger = original.deriveFont(newSize);
Where newSize is either a float or an int. This is well documented in the JavaDoc for Font as other people have pointed out
MrWiggles
2009-06-25 13:40:27
+1. @Raji: In addition, if you want to increase the font size on the GUI components this way you can do it while retaining the font set and format. For example: myLabel.setFont(myLabel.getFont().deriveFont(20)); You can then implement a recursive algorithm which performs this operation on the entire component hierarchy. Just an idea.
kd304
2009-06-25 14:08:11
+1
A:
Assuming that you want to change the font size on a specific JLabel
, you can do:
label.setFont(label.getFont().deriveFont(newSize));
Make sure that newSize
is a float
not an int
.
Avrom
2009-06-26 20:14:38