Rom*_*eau 55
尝试:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
打电话给......
setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
Run Code Online (Sandbox Code Playgroud)
Ami*_*far 37
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 */);
Run Code Online (Sandbox Code Playgroud)
资料来源:http://www.jguru.com/faq/view.jsp? EID = 340519
Bom*_*mbe 18
java -Dswing.aatext=true -Dswing.plaf.metal.controlFont=Tahoma -Dswing.plaf.metal.userFont=Tahoma …
Run Code Online (Sandbox Code Playgroud)
这不仅可以在您的完整UI上设置Tahoma,还可以启用抗锯齿功能,使任何字体立即变得更加美观.
我认为这更好,称之为当前的laf,而不是整个UIManager把它
UIManager.getLookAndFeelDefaults()
.put("defaultFont", new Font("Arial", Font.BOLD, 14));
Run Code Online (Sandbox Code Playgroud)
在实例化JFrame对象之前的主要位置.它对我来说很完美.请记住,对于没有指定字体的组件,这是默认字体.
来源:http://www.java.net/node/680725
受 Romain Hippeau 的启发,如果您只想设置字体大小,请使用此代码。
for (Map.Entry<Object, Object> entry : javax.swing.UIManager.getDefaults().entrySet()) {
Object key = entry.getKey();
Object value = javax.swing.UIManager.get(key);
if (value != null && value instanceof javax.swing.plaf.FontUIResource) {
javax.swing.plaf.FontUIResource fr=(javax.swing.plaf.FontUIResource)value;
javax.swing.plaf.FontUIResource f = new javax.swing.plaf.FontUIResource(fr.getFamily(), fr.getStyle(), FONT_SIZE);
javax.swing.UIManager.put(key, f);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,设置默认字体的方式取决于您使用的外观。Romain Hippeau 描述的解决方案适用于很多 LAF,但不适用于 Nimbus。sherif 发布的那篇文章在 Nimbus 上工作得很好,但对其他人(例如 Metal)则不行。
将两者结合可以适用于大多数 LAF,但这些解决方案都不适用于 GTK+ LAF。
我认为(但我不确定),没有跨平台的解决方案。