本人是 linux 新手
系统:
Fedora Core 4 + Eclipse 3.1.1 + jdk1.5
写了个 Swing 的 窗口
按钮(JButton)上的中文变成了一个个的方框
窗口(JFrame)的标题栏上中文到是正常.
系统,Eclipse和jdk都是新装的.请教如何才能正常显示中文.
系统:
Fedora Core 4 + Eclipse 3.1.1 + jdk1.5
写了个 Swing 的 窗口
按钮(JButton)上的中文变成了一个个的方框
窗口(JFrame)的标题栏上中文到是正常.
系统,Eclipse和jdk都是新装的.请教如何才能正常显示中文.
String str="中国";
byte [] buf = new byte[str.getBytes().length];
buf = str.getBytes("GB2312");
str = String(buf,0,str.getBytes().length)
jbutton.add(str)
str = String(buf,0,str.getBytes().length)
这句应该加个new
str = new String(buf,0,str.getBytes().length)
测试用的 代码如下import javax.swing.*;public class TestChina { JFrame f;
JButton b;
String s;
TestChina() {
f = new JFrame();
b = new JButton();
s = "中文";
byte[] buf = new byte[s.getBytes().length];
try{
buf = s.getBytes("GB2312");
s = new String(buf,0,s.getBytes().length);
}
catch (Exception e)
{
e.printStackTrace();
}
b.setText(s);
f.getContentPane().add(b);
f.pack();
f.setBounds(100,100,100,100);
f.setDefaultCloseOperation(3);
f.setVisible(true);
}
public static void main(String[] args) {
new TestChina(); }
}错误
java.lang.StringIndexOutOfBoundsException: String index out of range: 6