I need to set the the default font for my application. Is there a way to do this that is not LaF dependent?
You can't actually change the size of an existing Font object. The best way to achieve a similar effect is to use the deriveFont(size) method to create a new almost identical Font that is a different size.
It doesn't have a default font. It depends on what LookandFeel you are using.
In Java, Font is a class that belongs to the java. awt package. It implements the Serializable interface. FontUIResource is the direct known subclass of the Java Font class. It represents the font that are used to render the text.
Figured it out:
Call with: setUIFont (new javax.swing.plaf.FontUIResource(new Font("MS Mincho",Font.PLAIN, 12)));
private static void setUIFont(javax.swing.plaf.FontUIResource f)
{
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements())
{
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource)
{
UIManager.put(key, f);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With