1

I've found this solution to change the font of the entire application, but the application has some fonts with bold and some plain (Like the ones in JTables). Using the method described there, everything becomes "plain" (In this case, "TRUETYPE"), even the menus. I want to preserve the default bolds.

    public static void main(String[] args) {
        setUIFont (new javax.swing.plaf.FontUIResource("VERDANA", Font.TRUETYPE_FONT, 14));
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    frame = new MainFrame();
                    toggleFrame(frame);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

Is there a way to change only the size, without changing the font name and style? (Turning everything bold is equally atrocious).

Community
  • 1
  • 1
Ericson Willians
  • 7,606
  • 11
  • 63
  • 114
  • 1
    You mean something like [this for example](http://stackoverflow.com/questions/34149453/java-swing-application-too-small-in-hidpi-computers/34152675#34152675)? - This will only affect the look and feel settings, if you're applying a font directly to component yourself, then I'd suggest storing it in the UIManager with `.font` key – MadProgrammer Mar 03 '17 at 07:30

1 Answers1

1

You can do a small modification to that solution.

public static void setUIFontSize(int newSize) {
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value != null
                && value instanceof javax.swing.plaf.FontUIResource) {
            FontUIResource oldFont = (FontUIResource) value;
            UIManager.put(key, oldFont.deriveFont((float) newSize));
        }
    }
}
Ericson Willians
  • 7,606
  • 11
  • 63
  • 114
hunter
  • 3,963
  • 1
  • 16
  • 19