本文介绍了设置Swing程序的默认字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何为我的整个Java swing程序设置默认的字体。从我的研究看来,它可以用 UIManager
来完成,与 LookAndFeel
有关,但是我找不到特别是如何做到这一点, UIManager
看起来相当复杂。
解决方案
尝试:
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(valueof instanceof javax.swing.plaf.FontUIResource)
UIManager.put(key,f);
$ / code $ / pre
$ b 通过...
setUIFont(new javax.swing.plaf.FontUIResource(Serif,Font.ITALIC,12));
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.
解决方案 try:
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);
}
}
Call by ...
setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
这篇关于设置Swing程序的默认字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
06-27 15:09