I was wondering how to set the default font for my entire Java swing program. From my research it appears it can be done with UIManager
, something to do with LookAndFeel
, but I can't find specifically how to do it, and the UIManager
appears pretty complicated.
To set the font for a Swing component, use its setFont() method of the component. JButton closeButton = new JButton("Close"); closeButton. setFont(f4);
Go to Format > Font > Font. + D to open the Font dialog box. Select the font and size you want to use. Select Default, and then select Yes.
Calibri has been Word's default font since 2007, when it replaced Times New Roman.
The default font of Java Swing components is Tahoma 11 plain.
try:
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); } }
Call by ...
setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
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 */);
Source: http://www.jguru.com/faq/view.jsp?EID=340519
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With