Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jTextArea - problem with \u

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it to heavy for YOU???
Could someone answer???
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks man.
It works good.
You are the best one.
Duke dollars for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic