O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

436
|
Chapter 11, Native Integration and Packaging
#86 Make Quick Look and Feel Changes
HACK
Text Components
Text components have font settings in addition to their colors. This lets you
set a component to use a different font style or size. You can even load a cus-
tom font from a file:
Font font = Font.createFont(Font.TRUETYPE_FONT,
new FileInputStream("dungeon.ttf"));
font = font.deriveFont(Font.BOLD,16f);
UIManager.put("Label.font",font);
This would look like Figure 11-12.
Most components also have margins that are defined by an
Insets object. A
text field with large insets:
UIManager.put("TextField.margin", new Insets(25,25,25,25));
would look like Figure 11-13.
Figure 11-11. A sample program with green components
Figure 11-12. A custom font

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required