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

后端 未结 6 1257
傲寒
傲寒 2020-12-30 12:21

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,         


        
6条回答
  •  一整个雨季
    2020-12-30 12:54

    The nimbus defaults are lazy created so setting 'defaultFont' before the screen is painted, will add the font to the parent defaults, and not to the nimbus defaults.

    Workaround: force nimbus to initialize the defaults and set then the defaults:

    NimbusLookAndFeel laf = new NimbusLookAndFeel();
    UIManager.setLookAndFeel(laf);
    laf.getDefaults().put("defaultFont", new Font("Monospaced", Font.BOLD, 12));
    

    Note: this code is more efficient then overriding getDefaults(), as suggested above.

提交回复
热议问题