Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes jTextArea - problem with \u Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jTextArea - problem with \u" Watch "jTextArea - problem with \u" New topic
Author

jTextArea - problem with \u

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
I have HashTable containing Strings with unicode characters. When I try:
jTextArea1.setText(hash_table.get(hash_item).toString());
I get the correct result except it fails in parsing unicode marks.
Why???
But when I try:
jTextArea1.setText("example \u0394");
everything is OK
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Is it to heavy for YOU???
Could someone answer???
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This simple example is working for me...



Does this example work for you?

I think your problem may be the way your data is being put into the hashtable. Maybe it's being added in as //u0394 and your program doesn't understand it's supposed to be parsed into a unicode character?

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Thanks anyway, but I've already tried that. My problem is a little bit different.
I have .txt file in Courier New (Western) font (-it's OK with Java) and I used:
BufferedReader b = new BufferedReader(new FileReader ("myFile.txt"));
classes in order to read whole lines of plain text that contains unicode \uXXXX
while (
...
hash_table.put(b.readLine(), b.readLine());
...
}
And everything compiles OK, run OK too, and when it comes to:
jTextArea1.setText(hash_table.get(some_hash_item));
I get the result, but the unicode mark isn't parsed. It is as it were in a text file. Here is an example of what I get in jTextArea field:

This is Greek symbol for micrometer \u03BC

As you can see there is no correct symbol.
Please try this and tell me what have you done.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Sorry I saw just after I had posted reply.
Casting is missing.
This is correct (like in my original application):
jTextArea1.setText((String)hash_table.get(some_hash_item));
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Hmmmm... this link might help you...

http://java.sun.com/docs/books/tutorial/i18n/text/convertintro.html

I *finally* got the sample code to actually work by doing adding a StringTokenizer to find Unicode values... Whenever a String is read from an external source, Java is smart enough to know to turn a "\" into a "\\"... since this is a special case, you have to add a StringTokenizer to check for UniCode codes...



-Nate
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Thanks man.
It works good.
You are the best one.
Duke dollars for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jTextArea - problem with \u