如何在整个Swing UI应用程序中更改字体 [英] How to change the Font in the entire Swing UI application

查看:142
本文介绍了如何在整个Swing UI应用程序中更改字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个swing应用程序。现在我想更改整个Swing应用程序的字体,以便所添加的任何组件都应该仅遵循该字体。
有什么办法可以达到同样的效果吗?

解决方案

  public static void setGlobalFont(Font font){
Enumeration keys = UIManager.getDefaults()。keys();
while(keys.hasMoreElements()){
Object key = keys.nextElement();
Object value = UIManager.get(key);
if(value instanceof Font){
UIManager.put(key,font);
}
}
}


I have made a swing application. Now I want to change the Font of entire Swing Application , so that any component being added should follow that Font only. Is there any way to achieve the same ?

解决方案

public static void setGlobalFont( Font font ) {  
        Enumeration keys = UIManager.getDefaults().keys();  
        while (keys.hasMoreElements() ) {  
            Object key = keys.nextElement();  
            Object value = UIManager.get( key );  
            if ( value instanceof Font ) {  
                UIManager.put( key, font );  
            }  
        }  
    }  

这篇关于如何在整个Swing UI应用程序中更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆