이 코드는 문자를 표시하고 다른 텍스트 영역에 해당 "유니 코드 문자열"대응 : 그래서
import java.awt.*;
import javax.swing.*;
public class FrameTest {
public static void main(String[] args) {
JFrame jf = new JFrame("Demo");
Container cp = jf.getContentPane();
cp.setLayout(new BorderLayout());
JTextArea ta1 = new JTextArea(20, 20);
JTextArea ta2 = new JTextArea(20, 20);
Character c = '\u0645';
ta1.setText("" + c);
String s = String.format("\\%04x", (int) c.charValue());
ta2.setText(s);
cp.add(ta1, BorderLayout.WEST);
cp.add(ta2, BorderLayout.EAST);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(500, 100);
jf.setVisible(true);
}
}
당신이있는 경우 이러한 문자의 긴 텍스트는 문자열을 통해 루프를 사용해야합니다 (을 사용).또는 getChars()
) 각 문자를 String.format("\\%04x", (int) c.charValue());
으로 처리하고 결과를 대상 문자열에 추가하십시오. , DIR을
잘못된 결과를 얻을 때 정확히 한 JTextArea에서 다른 JTextArea로 텍스트를 전송합니까? – tangens
또한 문제는 UTF-8과 관련하여 ** 아무것도 ** 없다는 점에 유의하십시오! –