首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >设置Swing程序的默认字体

设置Swing程序的默认字体
EN

Stack Overflow用户
提问于 2011-09-16 01:13:31
回答 10查看 86.3K关注 0票数 70

我想知道如何为我的整个Java swing程序设置默认字体。从我的研究来看,这似乎可以用UIManager完成,与LookAndFeel有关,但我找不到具体如何做到这一点,而且UIManager看起来相当复杂。

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2011-09-16 01:21:18

尝试:

代码语言:javascript
复制
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);
      }
    } 

通过..。

代码语言:javascript
复制
setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
票数 67
EN

Stack Overflow用户

发布于 2011-09-16 01:18:21

代码语言:javascript
复制
UIManager.put("Button.font", /* font of your liking */);
UIManager.put("ToggleButton.font", /* font of your liking */);
UIManager.put("RadioButton.font", /* font of your liking */);
UIManager.put("CheckBox.font", /* font of your liking */);
UIManager.put("ColorChooser.font", /* font of your liking */);
UIManager.put("ComboBox.font", /* font of your liking */);
UIManager.put("Label.font", /* font of your liking */);
UIManager.put("List.font", /* font of your liking */);
UIManager.put("MenuBar.font", /* font of your liking */);
UIManager.put("MenuItem.font", /* font of your liking */);
UIManager.put("RadioButtonMenuItem.font", /* font of your liking */);
UIManager.put("CheckBoxMenuItem.font", /* font of your liking */);
UIManager.put("Menu.font", /* font of your liking */);
UIManager.put("PopupMenu.font", /* font of your liking */);
UIManager.put("OptionPane.font", /* font of your liking */);
UIManager.put("Panel.font", /* font of your liking */);
UIManager.put("ProgressBar.font", /* font of your liking */);
UIManager.put("ScrollPane.font", /* font of your liking */);
UIManager.put("Viewport.font", /* font of your liking */);
UIManager.put("TabbedPane.font", /* font of your liking */);
UIManager.put("Table.font", /* font of your liking */);
UIManager.put("TableHeader.font", /* font of your liking */);
UIManager.put("TextField.font", /* font of your liking */);
UIManager.put("PasswordField.font", /* font of your liking */);
UIManager.put("TextArea.font", /* font of your liking */);
UIManager.put("TextPane.font", /* font of your liking */);
UIManager.put("EditorPane.font", /* font of your liking */);
UIManager.put("TitledBorder.font", /* font of your liking */);
UIManager.put("ToolBar.font", /* font of your liking */);
UIManager.put("ToolTip.font", /* font of your liking */);
UIManager.put("Tree.font", /* font of your liking */);

来源:http://www.jguru.com/faq/view.jsp?EID=340519

票数 41
EN

Stack Overflow用户

发布于 2011-09-16 02:15:17

代码语言:javascript
复制
java -Dswing.aatext=true -Dswing.plaf.metal.controlFont=Tahoma -Dswing.plaf.metal.userFont=Tahoma …

这不仅会在你的完整UI上设置Tahoma,而且还会打开抗锯齿功能,这会让任何字体立即变得更漂亮。

票数 20
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7434845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档