This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Charset problem in JOptionPane on Applet

 
Marco Tulio Borges
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, there! I have an applet that needs to show messages to users using JOptionPane. The web page containing the applet is configured to use ISO-8859-1, but when the applet displays a message using JOptionPane, the message appears with squares in place of "é", "ã", "ó" or any characters with these signs.

The page that contains the applet is:


Do you have any ideia of what might be happening.
I am using:
  • Java 6 update 20
  • IE 8 and FF 3.6 (both presented the same problem)
  • Tomcat 5.5


  • 10x in advance!
     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The web page encoding is irrelevant to the applet. What font is the applet using? Does the font contain the characters you're trying to display? Are you talking about the dialog title or the dialog contents?
     
    Marco Tulio Borges
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, I did not change the default font. I have tried the default look and feel and the Windows look and feel, both had the same problems. The problems only happen when I am using the applet on the browser: it does not happen when the applet is running on AppletViewer.

    About the Font, I haven't changed it, since I am using:



    I tried using getFont() from JApplet, but it returns null, however, when I try (using Windows look and feel):

    then I get:
    Console wrote:javax.swing.plaf.FontUIResource[family=Tahoma,name=Tahoma,style=plain,size=11]

    both on browser and on AppletViewer.

    Ulf Dittmer wrote:Are you talking about the dialog title or the dialog contents?

    The contents.


    As an addition (and I am editing the post because of this), I tried the call:

    and got a true as a result.
     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Keeping accented characters in a Java source file is a tricky business - for that to work you'd need to specify the file encoding during compilation; are you doing that? If not, try using the Java Unicode notation (\uxxxx) for those characters.
     
    Marco Tulio Borges
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ulf Dittmer wrote:you'd need to specify the file encoding during compilation; are you doing that?

    Yes, I live in Brazil, so most of our messages and documentation come in ISO-8859-1 flavour. The source code is fine. What really bugs me is that in AppletViewer, the same code works as it is supposed to work... Hummm... But then again, before it goes to the browser, it passes through an ant script for compiling and packaging. I will check into that and get back here.
     
    Marco Tulio Borges
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That's it! The problem was not in the saved file, but in the way the file was handled by Ant. While the file was saved, compiled and tested in Eclipse with the AppletViewer, it ran just fine. But when I was compiling, packaging and signing it with ant before the applet went to the web server, there was a problem: ant was not using the same encoding as Eclipse to compile the files. I just added the encoding parameter to the javac tag of the ant build and it worked! Thanks for the tip about the file encoding!
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic