• java 菜单 中文 乱码问题解决方案(使用idea/eclipse) swing MenuItem乱码


     

    java swing MenuItem乱码

    用java开发一个带有托盘图标的程序, 
    其它模块的中文显示都是正常的,比如: 
     
    就只有托盘中点击小图标时弹出的菜单中的中文是方框(中文方块),如下: 
     

    按照一般的经验,以为是字体没设置好,就用以下代码设置字体: 
    Java代码  收藏代码
    1. Font f = new Font("u5faeu8f6fu96c5u9ed1", Font.PLAIN, 11);//宋体  
    2. UIManager.put("Label.font",f);  
    3.         UIManager.put("Label.foreground",Color.black);  
    4.         UIManager.put("Button.font",f);  
    5.         UIManager.put("Menu.font",f);  
    6.         UIManager.put("MenuItem.font",f);  
    7.         UIManager.put("List.font",f);  
    8.         UIManager.put("CheckBox.font",f);  
    9.         UIManager.put("RadioButton.font",f);  
    10.         UIManager.put("ComboBox.font",f);  
    11.         UIManager.put("TextArea.font",f);  
    12.         UIManager.put("EditorPane.font",f);  
    13.         UIManager.put("ScrollPane.font",f);  
    14.         UIManager.put("ToolTip.font",f);  
    15.         UIManager.put("TextField.font",f);  
    16.         UIManager.put("TableHeader.font",f);  
    17.         UIManager.put("Table.font",f);  

    完了中文还是方块,那就用以下代码打印字体: 
    Java代码  收藏代码
    1. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();  
    2. String script[] = ge.getAvailableFontFamilyNames();  
    3. for(String s:script){  
    4. System.out.print(s+",");  
    5. }  

    发现明明写着有宋体。这下郁闷了,试了一下午,还是没有搞定。 
    终于在网上找到了救星(参考:http://scnjl.iteye.com/blog/1282172)。 
    原来是myeclipse的运行参数问题,真想骂人啊我。。。 
    下面说说解决: 
    第一: 
    在你的具有main函数的类也即你应用运行的主类上点击右键,选择Run As中的Run Configurations,如下图: 


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


    在次运行 

     
  • 相关阅读:
    PHP实现异步调用方法研究
    碰到这个SB错误,'Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded.点办
    ubuntu中vim找不到配色方案blackboard
    解决宿主机不能访问虚拟机CentOS中的站点 | 更新CentOS防火墙设置开启80端口访问
    在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware
    PHP header() http各种状态码大全查询
    JS创建对象的方式
    buuctf-web [极客大挑战 2019]Upload 1
    buuctf-web 新生赛]Upload 1
    buuctf-web easy_tornado 1
  • 原文地址:https://www.cnblogs.com/duanweishi/p/8592928.html
Copyright © 2020-2023  润新知