`

解决substance.jar标题栏中文乱码的方法

阅读更多

由于Swing中默认都是使用了tohoma字体,而不是 Dialog 这样的family font。

 

 

public class Main {
    @SuppressWarnings("unchecked")
    public static void initGlobalFontSetting(Font fnt) {
        FontUIResource fontRes = new FontUIResource(fnt);
        for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel());
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                    initGlobalFontSetting(new Font("微软雅黑",Font.PLAIN,12));
                    new MainFrame();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

分享到:
评论
1 楼 BenoWay 2011-03-23  
我这里没有用。
try {
					SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
				} catch (Exception e) {
					
				}
				JFrame.setDefaultLookAndFeelDecorated(true);
				Font font = new Font("Dialog", Font.LAYOUT_NO_LIMIT_CONTEXT, 14);

				FontUIResource fontRes = 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, fontRes);
				}
				
				JFrame frame = new JFrame("window窗口乱码");
				frame.setLayout(new FlowLayout());
				frame.add(new JButton("button按钮"));
				frame.add(new JCheckBox("check选择"));
				frame.add(new JLabel("label标签"));
				frame.setUndecorated(true);
				frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

				frame.setSize(new Dimension(300, 80));
				frame.setLocationRelativeTo(null);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				frame.setVisible(true);
Global site tag (gtag.js) - Google Analytics