在Swing中设置字体的大小


第一种

这段代码在jframe显示前调用,比如main方法开始就调用它:
Font font = new Font("宋体",Font.PLAIN,12);
        UIManager.put("Button.font", font);
        UIManager.put("CheckBox.font", font);
        UIManager.put("CheckBoxMenuItem.acceleratorFont", font);
        UIManager.put("CheckBoxMenuItem.font", font);
        UIManager.put("ColorChooser.font", font);
        UIManager.put("ComboBox.font", font);
        UIManager.put("DesktopIcon.font", font);
        UIManager.put("EditorPane.font", font);
        UIManager.put("FormattedTextField.font", font);
        UIManager.put("InternalFrame.titleFont", font);
        UIManager.put("Label.font", font);
        UIManager.put("List.font", font);
        UIManager.put("Menu.acceleratorFont", font);
        UIManager.put("Menu.font", font);
        UIManager.put("MenuBar.font", font);
        UIManager.put("MenuItem.acceleratorFont", font);
        UIManager.put("MenuItem.font", font);
        UIManager.put("OptionPane.font", font);
        UIManager.put("Panel.font", font);
        UIManager.put("PasswordField.font", font);
        UIManager.put("PopupMenu.font", font);
        UIManager.put("ProgressBar.font", font);
        UIManager.put("RadioButton.font", font);
        UIManager.put("RadioButtonMenuItem.acceleratorFont", font);
        UIManager.put("RadioButtonMenuItem.font", font);
        UIManager.put("ScrollPane.font", font);
        UIManager.put("Spinner.font", font);
        UIManager.put("TabbedPane.font", font);
        UIManager.put("Table.font", font);
        UIManager.put("TableHeader.font", font);
        UIManager.put("TextArea.font", font);
        UIManager.put("TextField.font", font);
        UIManager.put("TextPane.font", font);
        UIManager.put("TitledBorder.font", font);
        UIManager.put("ToggleButton.font", font);
        UIManager.put("ToolBar.font", font);
        UIManager.put("ToolTip.font", font);
        UIManager.put("Tree.font", font);
        UIManager.put("Viewport.font", font);


第二种

private   void   makeFont(){
  try   {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 Font   font=new   Font( "JDialog ",Font.PLAIN,12);
String   names[]={ "Label ", "CheckBox ", "PopupMenu ",
    "MenuItem ", "CheckBoxMenuItem ", "JRadioButtonMenuItem ",
    "ComboBox ", "Button ", "Tree ", "ScrollPane ", "TabbedPane ",
    "EditorPane ", "TitledBorder ", "Menu ", "TextArea ", "OptionPane ",
    "MenuBar ", "ToolBar ", "ToggleButton ", "ToolTip ", "ProgressBar ",
    "TableHeader ", "Panel ", "List ", "ColorChooser ", "PasswordField ",
    "TextField ", "Table ", "Label ", "Viewport ", "RadioButtonMenuItem ",

    "RadioButton ", "DesktopPane ", "InternalFrame "

                     };

            for(int   i=0;i

                   UIManager.put(names[i]+ ".font ",font);

}

UIManager.put( "OptionPane.messageFont ",font);

UIManager.put( "OptionPane.buttonFont ",font);

UIManager.put( "Label.foreground ",Color.black);

UIManager.put( "Border.foreground ",Color.black);

UIManager.put( "TitledBorder.titleColor ",Color.black);
}catch(Exception   e){
      e.printStackTrace();
}

}

你可能感兴趣的:(Swing)