【发布时间】:2015-08-09 09:00:52
【问题描述】:
如何更改我的 java 应用程序中显示的所有组件的字体?
我用 UIManager 试过了
UIManager.put("TextField.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11));
UIManager.put("Label.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11));
UIManager.put("ComboBox.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11))
奇怪的是,这改变了文本字段的字体,但不适用于 JLabels 或 JComboBoxes
然后我尝试通过遍历 UIManager 知道的所有键来设置字体:
public static void setUIFont(FontUIResource f) {
Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
FontUIResource orig = (FontUIResource) value;
Font font = new Font(f.getFontName(), orig.getStyle(), f.getSize());
FontUIResource fontUIResource = new FontUIResource(font);
UIManager.put(key, fontUIResource);
UIManager.getDefaults().put(key, fontUIResource);
UIManager.getLookAndFeel().getDefaults().put(key, fontUIResource);
}
}
}
这段代码根本不起作用。
我必须说我使用 Synthetica 作为 LookAndFeel...所以我不知道这会如何干扰我通过 UIManager 进行的手动设置。
【问题讨论】:
标签: java swing fonts uimanager