其它模块的中文显示都是正常的,比如:

就只有托盘中点击小图标时弹出的菜单中的中文是方框(中文方块),如下:

按照一般的经验,以为是字体没设置好,就用以下代码设置字体:
- Font f = new Font("u5faeu8f6fu96c5u9ed1", Font.PLAIN, 11);//宋体
- UIManager.put("Label.font",f);
- UIManager.put("Label.foreground",Color.black);
- UIManager.put("Button.font",f);
- UIManager.put("Menu.font",f);
- UIManager.put("MenuItem.font",f);
- UIManager.put("List.font",f);
- UIManager.put("CheckBox.font",f);
- UIManager.put("RadioButton.font",f);
- UIManager.put("ComboBox.font",f);
- UIManager.put("TextArea.font",f);
- UIManager.put("EditorPane.font",f);
- UIManager.put("ScrollPane.font",f);
- UIManager.put("ToolTip.font",f);
- UIManager.put("TextField.font",f);
- UIManager.put("TableHeader.font",f);
- UIManager.put("Table.font",f);
完了中文还是方块,那就用以下代码打印字体:
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- String script[] = ge.getAvailableFontFamilyNames();
- for(String s:script){
- System.out.print(s+",");
- }
发现明明写着有宋体。这下郁闷了,试了一下午,还是没有搞定。
终于在网上找到了救星(参考:http://scnjl.iteye.com/blog/1282172)。
原来是myeclipse的运行参数问题,真想骂人啊我。。。
下面说说解决:
第一:
在你的具有main函数的类也即你应用运行的主类上点击右键,选择Run As中的Run Configurations,如下图:

第二,在Arguments标签下的VM arguments中添加下面这行参数代码,然后点击应用。
-Dfile.encoding=GB18030

在次运行
