tags:

views:

470

answers:

5

Are there any built-in methods in Java to increase Font size?

A: 

Of course. Have a look at the JavaDoc for Font

willcodejavaforfood
+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
+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
+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
+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
A: 

you can set the property swing.plaf.metal.controlFont when running you application:

java -Dswing.plaf.metal.controlFont=Dialog-50 YourMainClass

in this example, you set the default font to be "Dialog" with size 50.

cd1
+1 for the Swing parametering
kd304