import java.awt.Font; import java.util.Enumeration; import javax.swing.UIManager; import javax.swing.plaf.FontUIResource; /** * 统一设置字体,父界面设置之后,所有由父界面进入的子界面都不需要再次设置字体 */ public class SetPersonalFont { public void InitGlobalFont(Font font) { FontUIResource globalFont = new FontUIResource(font); for (Enumeration keys = UIManager.getDefaults().keys(); keys .hasMoreElements();) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof FontUIResource) { UIManager.put(key, globalFont); } } } } //main方法部分代码: SetPersonalFont setfont = new SetPersonalFont(); setfont.InitGlobalFont(new Font("monspaced", Font.PLAIN, 13)); MainFrame main = new MainFrame(); main.setVisible(true);