用java开发一个带有托盘图标的程序,
其它模块的中文显示都是正常的,比如:
就只有托盘中点击小图标时弹出的菜单中的中文是方框(中文方块),如下:
按照一般的经验,以为是字体没设置好,就用以下代码设置字体:
Font f = new Font("\u5fae\u8f6f\u96c5\u9ed1", 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
在次运行
文章来源:
http://hi.baidu.com/happyroad_/item/a58a969adc33a18159146149
- 大小: 3 KB
- 大小: 5.8 KB
- 大小: 80.1 KB
- 大小: 72.4 KB
- 大小: 3.3 KB
分享到:
相关推荐
android 开发MenuItem显示中文乱码.docx
JavaFX+Jfoenix 学习笔记系列文章的JavaFX+Jfoenix 学习笔记(十)--系统托盘及解决中文乱码问题源码
java售房系统 swing组件 menu1=new Menu("系统管理"); menu2=new Menu("房屋管理"); menu3=new Menu("销售管理"); menu4=new Menu("查询信息"); item1=new MenuItem("修改密码"); item3=new ...
wpf菜单MenuItem样式经典源代码,绝对经典,
WPF中MenuItem原生样式
import javax.swing.JOptionPane; import java.io.*; import sun.audio.*; class Ex extends Frame implements ActionListener { MenuBar menubar=new MenuBar();//菜单 Menu fileMenu,editMenu,helpMenu;...
wpf菜单MenuItem样式经典源代码,绝对经典,颜色根据自己需要修改
import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; import java.awt.event.ActionEvent; import java.awt.event....
import javax.swing.JColorChooser; public class Jishiben extends Frame implements ActionListener { MenuBar menuBar; //定义菜单条 TextArea textArea=new TextArea(20,50);//定义文本区 public OptionOfFile...
用Java编写的一个五指棋 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.URL; @SuppressWarnings("serial") public class ChessMap extends JFrame { private ImageIcon map...
Java与数据库连接的小作业 package edu.dl; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class StudentWindow extends Frame implements ...
java实现的记事本源代码 FileDialog load, save; MenuBar menubar; Menu menu1, menu2, menu3, menu4; MenuItem item1, item2, item3, item4, item5, item6, item7; MenuItem item01, item02, item03, item04, ...
自己项目中做的WPF菜单项目测试
11. import java.awt.MenuItem; 12. import java.awt.PopupMenu; 13. import java.awt.Rectangle; 14. import java.awt.SystemTray; 15. import java.awt.Toolkit; 16. import java.awt.TrayIcon; 17. import ...
import javax.swing.*; public class EchoServerTest extends JFrame implements Runnable{ JTextArea textArea; JTextArea textArea1; ServerSocket serverSocket; Socket socket; SenderButton sender; ...
(1) 现在java 图形界面设计一般运用javax.swing包. (2)设计图形界面的步骤: 设计最外层的容器如:JFrame确定容器的布局方式往容器中加其他组件(容器或标准GUI组件)编写事件处理程序. (3)一般的标准GUI...
menuItem =new JMenuItem("新建",KeyEvent.VK_N);//创建File子菜单 menuItem.addActionListener(al); menu.add(menuItem); menuItem =new JMenuItem("打开",KeyEvent.VK_O); menuItem.addActionListener(al...
import javax.swing.*; public class MyCalculator extends Frame implements ActionListener { JTextField txt = new JTextField(""); StringBuffer copyBoard=new StringBuffer(20); private String cmd = ...
JMenuItem menuItem = new JMenuItem("New Project...", new ImageIcon("images/newproject.png")); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.getAccessibleContext().setAccessibleDescription( "New ...
默认的MenuItem样式比较普通,这次自定义MenuItem的样式也只是对MenuItem的颜色风格进行变化。需要其他功能的变化,大家可以根据样式代码进行扩展。 MenuItem的样式代码: <!--MenuItem--> <Style Target...