为 Java 应用程序设置全局字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5824342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting the Global Font for a Java Application
提问by user489041
I need to set the the default font for my application. Is there a way to do this that is not LaF dependent?
我需要为我的应用程序设置默认字体。有没有一种不依赖于 LaF 的方法来做到这一点?
采纳答案by user489041
Figured it out:
弄清楚了:
Call with:setUIFont (new javax.swing.plaf.FontUIResource(new Font("MS Mincho",Font.PLAIN, 12)));
致电:setUIFont (new javax.swing.plaf.FontUIResource(new Font("MS Mincho",Font.PLAIN, 12)));
private static void setUIFont(javax.swing.plaf.FontUIResource f)
{
java.util.Enumeration<Object> 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);
}
}
}
回答by kleopatra
for better control about how/which fonts to replace - in a LAF independent way, but controllable per-laf - have a look at the JGoodies Looks project
为了更好地控制如何/哪些字体替换 - 以独立于 LAF 的方式,但每个 laf 是可控的 - 看看 JGoodies Looks 项目
http://java.net/projects/looks
http://java.net/projects/looks
It allows to swap entire FontSets (that's a collection of semantic fonts, like control, dialog, message) at runtime.
它允许在运行时交换整个 FontSets(这是语义字体的集合,如控件、对话框、消息)。