Unicode problem

Hi,

I wrote this code.

JTextArea textarea = new JTextArea ( );

textarea.addKeyListener (

new KeyAdapter ( ) {

public void keyPressed ( KeyEvent event ) {

int a = event.getKeyChar ( );

if ( a == 97 )

textarea.setText ( "\u0627");

}});

It is working well but with unicode it also displays english character "a" but i just want unicode character. How can i get rid of this problem.

[448 byte] By [pasion_of_christa] at [2007-10-2 21:40:53]
# 1
KeyListener is the wrong tool for this job. The simplest solution is probably to use a DocumentFilter. Try reading the API doc for AbstractDocument.
uncle_alicea at 2007-7-14 0:55:44 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hi,

>I wrote this code.

>JTextArea textarea = new JTextArea ( );

>textarea.addKeyListener (

> new KeyAdapter ( ) {

>public void keyPressed ( KeyEvent event ) {

> int a = event.getKeyChar (

> );

>if ( a == 97 )

> textarea.setText ( "\u0627");

>}});

> well but with unicode it also displays english

> character "a" but i just want unicode character. How

> can i get rid of this problem.

Are you trying to display "\u0627" instead of "a" on the textarea?

If that's the case, you just add an escape character "\".

like this.

if ( a == 97 )

textarea.setText ( "\\u0627"); // notice the double backslashes

Good luck

:D

TikkyChaia at 2007-7-14 0:55:44 > top of Java-index,Java Essentials,Java Programming...
# 3
Oh! By the way, this is not a unicode problem. It's just the way Java works.:D
TikkyChaia at 2007-7-14 0:55:44 > top of Java-index,Java Essentials,Java Programming...