Java: Altering UI fonts (Nimbus) doesn't work!

Posted by ivan_ivanovich_ivanoff on Stack Overflow See other posts from Stack Overflow or by ivan_ivanovich_ivanoff
Published on 2009-06-04T08:54:08Z Indexed on 2010/04/04 23:23 UTC
Read the original article Hit count: 328

Filed under:
|
|
|
|

Hello!

I'm referring to this Nimbus reference.

I tried to set global Font to be slightly larger:

UIManager.put("defaultFont", new Font(Font.SANS_SERIF, 0, 16));

...works only for the menu but nothing else (buttons, labels).

I tried to change labels and buttons fonts with

UIManager.put("Button.font", new Font(Font.SANS_SERIF, 0, 16));
UIManager.put("Label.font", new Font(Font.SANS_SERIF, 0, 16));

but the font remains.

The only thing that worked for me was deriving a font:

someButton.setFont(someButton.getFont().deriveFont(16f));

But this is not an option, since this must be done for each element manually.

Note, that deriving a font for UIManager doesn't work either:

UIManager.put("Label.font",
    UIManager.getFont("Label.font").deriveFont(16f));

I tested everything under Linux and Windows: same behavior.

I just can't understand how an API can be so messy. If a method is called setFont(..) then I expect it to set the font. If this method fails to set the font in any thinkable circumstances, then it should be deprecated.

EDIT:
The problem not only applies to Nimbus, but also to the default LAF.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing