I need to set the the default font for my application. Is there a way to do this that is not LaF dependent?
Setting the Global Font for a Java Application
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);
}
}
}
hmm .. what a strange requirement: are you sure you want the exact same font for everything? labels, textComponents, headers, borders, whatever? Users might be confused. –
Corycorybant
Yea, I need it to be the same font. Reason being is I need it to be a custom font we use to support special characters. Everything in the program is 12 point font, so size and all that shouldnt be an issue. –
Tanker
for better control about how/which fonts to replace - in a LAF independent way, but controllable per-laf - have a look at the JGoodies Looks project
http://java.net/projects/looks
It allows to swap entire FontSets (that's a collection of semantic fonts, like control, dialog, message) at runtime.
Awesome, ill have to check into this –
Tanker
© 2022 - 2024 — McMap. All rights reserved.