i have 2 JTextArea that one of these contain Unicode Code point like this \u0645 i want another JTextArea
show Character representation of this Unicode code point.but when pass this code point to JTextArea , it show
code point not Character but if i set code point to JTextArea setText method directly it work correctly !
why ? and which can i pass String of Codepoint from one JTextArea to another ?
thanks
This code displays a character, and in the other text-area the corresponding "unicode string" counterpart:
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);
}
}

So if you have a long text of such characters, you would need to loop through the string character by character, (using getCharAt(int) or getChars()) and process each character with String.format("\\%04x", (int) c.charValue()); and append the result to the target string. (Preferrably using a StringBuffer.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With