设置 Swing 程序的默认字体 [英] Setting the Default Font of Swing Program
本文介绍了设置 Swing 程序的默认字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何为我的整个 Java Swing 程序设置默认字体.从我的研究来看,它似乎可以用 UIManager
来完成,这与 LookAndFeel
有关,但我找不到具体的方法,以及 UIManager
看起来很复杂.
I was wondering how to set the default font for my entire Java swing program. From my research it appears it can be done with UIManager
, something to do with LookAndFeel
, but I can't find specifically how to do it, and the UIManager
appears pretty complicated.
推荐答案
尝试:
public static void setUIFont (javax.swing.plaf.FontUIResource f){
java.util.Enumeration 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);
}
}
通过...调用
setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
这篇关于设置 Swing 程序的默认字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文