• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

jTextArea - problem with \u

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it to heavy for YOU???
Could someone answer???
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks man.
It works good.
You are the best one.
Duke dollars for you.
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic