Swing技巧. 设置全局字体

Swing技巧. 设置全局字体(sun jdk)

为什么要这么做?

   因为java默认的字体显示中文都很难看

   因为比如jgoodies这样的skin默认不支持中文

   因为jdk1.4中文字体mapping有严重bug,用过IDEA的人都知道

   因为大家只有sun的jdk可用,ibm的,bea的都不适合跑client

if you are smart....
//设置全局字体
public static void initGlobalFontSetting(Font fnt){
    FontUIResource fontRes 
= new FontUIResource(fnt);
    
for(Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();){
        Object key 
= keys.nextElement();
        Object value 
= UIManager.get(key);
        
if(value instanceof FontUIResource)
            UIManager.put(key, fontRes);
    }
}
if you aren't...

Font font = new Font("Dialog",Font.PLAIN,12);
UIManager.put(
"ToolTip.font",font);
UIManager.put(
"Table.font",font);
UIManager.put(
"TableHeader.font",font); 
UIManager.put(
"TextField.font",font); 
UIManager.put(
"ComboBox.font",font); 
UIManager.put(
"TextField.font",font); 
UIManager.put(
"PasswordField.font",font); 
UIManager.put(
"TextArea.font",font); 
UIManager.put(
"TextPane.font",font); 
UIManager.put(
"EditorPane.font",font); 
UIManager.put(
"FormattedTextField.font",font); 
UIManager.put(
"Button.font",font); 
UIManager.put(
"CheckBox.font",font); 
UIManager.put(
"RadioButton.font",font); 
UIManager.put(
"ToggleButton.font",font); 
UIManager.put(
"ProgressBar.font",font); 
UIManager.put(
"DesktopIcon.font",font); 
UIManager.put(
"TitledBorder.font",font); 
UIManager.put(
"Label.font",font); 
UIManager.put(
"List.font",font); 
UIManager.put(
"TabbedPane.font",font); 
UIManager.put(
"MenuBar.font",font); 
UIManager.put(
"Menu.font",font); 
UIManager.put(
"MenuItem.font",font); 
UIManager.put(
"PopupMenu.font",font); 
UIManager.put(
"CheckBoxMenuItem.font",font); 
UIManager.put(
"RadioButtonMenuItem.font",font); 
UIManager.put(
"Spinner.font",font); 
UIManager.put(
"Tree.font",font); 
UIManager.put(
"ToolBar.font",font); 
UIManager.put(
"OptionPane.messageFont",font); 
UIManager.put(
"OptionPane.buttonFont",font); 
posted @   tech.cap  阅读(878)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示