Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the Default Font of Swing Program

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.

like image 225
Connor Neville Avatar asked Sep 15 '11 17:09

Connor Neville


People also ask

How do I change the font on my Swing?

To set the font for a Swing component, use its setFont() method of the component. JButton closeButton = new JButton("Close"); closeButton. setFont(f4);

How do I set my default font?

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.

What is the default font style?

Calibri has been Word's default font since 2007, when it replaced Times New Roman.

What is the default font size in Java?

The default font of Java Swing components is Tahoma 11 plain.


2 Answers

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)); 
like image 158
Romain Hippeau Avatar answered Oct 16 '22 21:10

Romain Hippeau


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

like image 30
Amir Raminfar Avatar answered Oct 16 '22 20:10

Amir Raminfar