Results 1 to 4 of 4
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default 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:

    Character Encoding with JOptionPane-01.png

    How can I see the characters correct in the text next to the question mark ? Thank you.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Character Encoding with JOptionPane

    Java Code:
    UIManager.put("OptionPane.messageFont", new FontUIResource(/*some Font that can display the characters*/));
    Font#canDisplayUpTo(...) can help you identify a suitable Font.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Character Encoding with JOptionPane

    Thank you for your help.

    This is what I have tried:

    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:");
    But it did not work?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. "unmappable character for encoding Cp1252"
    By Pojahn_M in forum New To Java
    Replies: 1
    Last Post: 09-20-2011, 05:40 PM
  2. Weird character encoding with mulitpartrequest
    By pokermagic in forum New To Java
    Replies: 0
    Last Post: 07-01-2011, 01:35 AM
  3. Character encoding in Java (Linux to Windows)
    By BeholdMyGlory in forum New To Java
    Replies: 2
    Last Post: 01-16-2009, 06:24 PM
  4. How to specify character encoding in JavaMail?
    By jfcup in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-24-2008, 07:55 PM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •