本人是 linux 新手
系统:
Fedora Core 4 + Eclipse 3.1.1 + jdk1.5
写了个 Swing 的 窗口
按钮(JButton)上的中文变成了一个个的方框
窗口(JFrame)的标题栏上中文到是正常.
系统,Eclipse和jdk都是新装的.请教如何才能正常显示中文.

解决方案 »

  1.   

    先把字符串编码.然后加到button中吧
      

  2.   


    String str="中国";
    byte [] buf = new byte[str.getBytes().length];
    buf = str.getBytes("GB2312");
    str = String(buf,0,str.getBytes().length)
    jbutton.add(str)
      

  3.   

    不好意思,发了才看见上面我发的那个有点问题.呵呵。。
    str = String(buf,0,str.getBytes().length)
    这句应该加个new 
    str = new String(buf,0,str.getBytes().length)
      

  4.   

    运行出错
    测试用的 代码如下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
      

  5.   

    那你用properties对象看看系统默认编码是什么..修改一下默认编码