File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Charset problem in JOptionPane on Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Charset problem in JOptionPane on Applet" Watch "Charset problem in JOptionPane on Applet" New topic
Author

Charset problem in JOptionPane on Applet

Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
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!


    .: SCJP 1.4 (95%) / SCWCD 1.4 (91%) / SCBCD (77%) :.
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us." - Calvin
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41863
        
      63
    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?


    Ping & DNS - my free Android networking tools app
    Marco Tulio Borges
    Ranch Hand

    Joined: Sep 14, 2004
    Posts: 45
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41863
        
      63
    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

    Joined: Sep 14, 2004
    Posts: 45
    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

    Joined: Sep 14, 2004
    Posts: 45
    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!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Charset problem in JOptionPane on Applet