JAVA Swing設置界面統一字體


//統一界面字體
  private static void InitGlobalFont(Font font) {
    FontUIResource fontRes = new FontUIResource(font);
    for (Enumeration<Object> keys = UIManager.getDefaults().keys();
         keys.hasMoreElements(); ) {
      Object key = keys.nextElement();
      Object value = UIManager.get(key);
      if (value instanceof FontUIResource) {
        UIManager.put(key, fontRes);
      }
    }

調用: InitGlobalFont(new Font("宋體", Font.PLAIN, 12));

 UIManager.put("Menu.font", new Font("宋體", Font.PLAIN, 12));//設置Menubar的字體 
 UIManager.put("MenuItem.font", new Font("宋體", Font.PLAIN, 12));//設置MenuItem的字體

//設置界面外觀風格

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());//操作系統的界面風格

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");//Java 6 Update 10后的新的Swing 跨平台界面外觀

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM