Applet with Plugin
How can I display non-ASCII-characters (e.g. Polish characters) inside a java-Applet.
This Applet is running on a Web-Browser (IE5.5 and NC4.7) with SUN-Java-Plugin
The Applet contains only AWT-Components.
Without Plugin the characters will be displayed correct.
Sourcecode
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(706,361);
add(label1);
label1.setText("\u0104\u0105\u0141\u0142\u0143\u0144\u0106\u0107\u0118\u0119");
label1.setFont(new Font("MonoSpaced",Font.PLAIN, 14));
}
java.awt.Label label1 = new java.awt.Label();
}
without Plugin
<HTML>
<HEAD>
<TITLE>Applet1</TITLE>
</HEAD>
<BODY>
<APPLET CODE = "Applet1.class" WIDTH = 706 HEIGHT = 361>
</APPLET>
</BODY>
</HTML>
with Plugin
<HTML>
<HEAD>
<TITLE>Applet1</TITLE>
</HEAD>
<BODY>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 706 HEIGHT = 361 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = "Applet1.class" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
</OBJECT>
</BODY>
</HTML>
[1595 byte] By [
rachid00] at [2007-9-26 2:05:32]

... or not. Reading the post before answering shouldn't do any harm... ;)
There are several bugs related to awt and unicode - maybe this is one of them. See eg.
http://developer.java.sun.com/developer/bugParade/bugs/4165604.html
http://developer.java.sun.com/developer/bugParade/bugs/4085120.html
I ran into a similar problem using Hebrew. The characters would display as a bunch of boxes. There are two ways around this problem:
1) Your font may not be able to support Unicode chars. Try switching you font to one that does. Microsoft has a font called ArialUnicode_MS - you can get it from their web site. This font supports all unicode characters.
This solution works for testing, but the problem then is that the guys in Poland may not have this font on their machines. Even if they do, the plug-in is required because ArialUnicode_MS is not a standard system font for Windows versions before Win2K. So, you may need to call them and find a system font on their machines which displays both english and polish characters, and set your font to that.
2) If the plug-in is not acceptable (which it usually isn't) you can use an AttributedCharacterIterator to draw your string. Set it up like this:
AttributedCharacterIterator aci = ((new AttributedString(content,map)).getIterator());
The map is a hashtable - you can set it to null for testing purposes. The content is your string.
For some reason, the AttributedCharacterIterator will draw the unicode characters.
Unfortunately, Label does not accept an AttributedCharacterIterator as an argument for a constructor. You will probably have to use Graphics.drawString(AttributedCharacterIterator iterator, int x, int y) to get the string to display. This means that you will probably have to change the way your program draws text (welcome to Internationalization).
Hope this helps.