Results 1 to 4 of 4
- 06-25-2012, 09:28 AM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Character Encoding with JOptionPane
Hi everyone.
I have a small code where I compare 2 files which contain pairs of key's and values.
An example is:
a.txt :
keyone=valueone
keytwo=valuetwo
b.txt :
keyone=somevalue
keytwo=someothervalue
keythree=differentvalue
Now what I do is because keythree is missing in a.txt, I show the user a JOptionPane and ask for the key and the value and write it on a.txt.
My problem is with encoding.
In JOptionPane when I write characters that are not English ( something from UTF - 8 ) I can see the character just fine and it is written in the file ok.
But when the same character is in the message part of the JOptionPane, I can not see the character correctly.
Please see the attached image:

How can I see the characters correct in the text next to the question mark ? Thank you.
- 06-25-2012, 10:02 AM #2
Re: Character Encoding with JOptionPane
Font#canDisplayUpTo(...) can help you identify a suitable Font.Java Code:UIManager.put("OptionPane.messageFont", new FontUIResource(/*some Font that can display the characters*/));
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-25-2012, 10:27 AM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Character Encoding with JOptionPane
Thank you for your help.
This is what I have tried:
But it did not work?Java Code:UIManager.put("JOptionPane.messageFont", new FontUIResource(new Font("UTF-8",1,12))); String str = JOptionPane.showInputDialog("\"" + key + "\"" + " found in (" + baseLocale + ") is missing in (" + targetLocale+")\n"+ "Translation in (" + baseLocale + ") for this key is: \"" + baseProperties.get(key)+"\"\n"+ "Enter desired translation for (" + targetLocale + ") for this key:");
- 06-25-2012, 04:35 PM #4
Re: Character Encoding with JOptionPane
Huh? Do you have a Font on your system named UTF-8? I certainly don't.
Also, don't use magic numbers in any situation where you should be using class constants. The constants Font.PLAIN, Font.BOLD etc are there for you to use -- so use them.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
"unmappable character for encoding Cp1252"
By Pojahn_M in forum New To JavaReplies: 1Last Post: 09-20-2011, 05:40 PM -
Weird character encoding with mulitpartrequest
By pokermagic in forum New To JavaReplies: 0Last Post: 07-01-2011, 01:35 AM -
Character encoding in Java (Linux to Windows)
By BeholdMyGlory in forum New To JavaReplies: 2Last Post: 01-16-2009, 06:24 PM -
How to specify character encoding in JavaMail?
By jfcup in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-24-2008, 07:55 PM -
reading text character by character
By bugger in forum New To JavaReplies: 2Last Post: 11-09-2007, 08:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks