[Java] java设置全局字体样式 →→→→→进入此内容的聊天室

来自 , 2019-08-09, 写在 Java, 查看 117 次.
URL http://www.code666.cn/view/4079016d
  1. import java.awt.Font;
  2. import java.util.Enumeration;
  3.  
  4. import javax.swing.UIManager;
  5. import javax.swing.plaf.FontUIResource;
  6.  
  7. /**
  8.  * 统一设置字体,父界面设置之后,所有由父界面进入的子界面都不需要再次设置字体
  9.  */
  10.  
  11. public class SetPersonalFont {
  12.         public void InitGlobalFont(Font font) {
  13.                 FontUIResource globalFont = new FontUIResource(font);
  14.                 for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys
  15.                                 .hasMoreElements();) {
  16.                         Object key = keys.nextElement();
  17.                         Object value = UIManager.get(key);
  18.                         if (value instanceof FontUIResource) {
  19.                                 UIManager.put(key, globalFont);
  20.                         }
  21.                 }
  22.         }
  23. }
  24.  
  25. //main方法部分代码:
  26.  
  27. SetPersonalFont setfont = new SetPersonalFont();
  28.                 setfont.InitGlobalFont(new Font("monspaced", Font.PLAIN, 13));
  29.                 MainFrame main = new MainFrame();
  30.                 main.setVisible(true);

回复 "java设置全局字体样式"

这儿你可以回复上面这条便签

captcha