可能重複:
how to implement UTF-8 format in Swing application?對Java Swing的UTF-8支持問題?
在Swing應用程序我有發送按鈕,一個文本區域和文本字段。
如果我按下發送鍵,我需要將文本從文本字段發送到文本區域
它在英語而不是在當地語言工作正常...
package package1;
import java.awt.*;
import java.awt.event.*;
import java.io.UnsupportedEncodingException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
class AEvent extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JTextField tf;
JTextArea area ;
Border border;
AEvent(){
area = new JTextArea(200,200);
area.setBounds(60,200,300,200);
border = BorderFactory.createLineBorder(Color.BLACK);
area.setBorder(border);
tf=new JTextField();
tf.setBounds(60,70,150,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
b.addActionListener(this);
add(b);
add(tf);
add(area);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
setSize(600,600);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
String s = null;
try {
s = new String(tf.getText().getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
area.setText(s);
}
public static void main(String args[]){
new AEvent();
}
}
請給一些想法或一些代碼,這將幫助我解決這個問題..
本地語言中行的例子是什麼?嘗試解決'JTextAre.setFont()' –
這應該工作。我也會懷疑一些字體問題,正如@NikolayKuznetsov所示。 –
@UwePlonus:這*是一個確切的副本。他甚至複製了無用的重複點。 –