Skip to content

Month: October 2015

Changing the Font of a JOptionPane

When working with a high-resolution monitors, like the one in the Surface Pro 3 (did I tell you how awesome this baby is?), programs need to be configured to use larger fonts, otherwise their text is completely unreadable, especially when you are presenting to someone else and don’t want them to have to come closer to your laptop when your UX comes up. One example is the Java JOptionPane, which looked tiny every time I used it. So after some drilling in the net, found the solution (and also a way to change other parameters in the dialog). The font is derived from a global property of the UIManager class called OptionPane.messageFont, which is changed like this:

javax.swing.UIManager.put("OptionPane.messageFont", new Font("Segoe UI", Font.PLAIN, 25));

To get all the available fonts in your environment, you can run the following code:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontNames = ge.getAvailableFontFamilyNames();
for (int index = 0; index < fontNames.length; index++) {

A very long list of options that can be managed using the UIManager can be found here.