I have a Java application in which rendering of Unicode characters is failing because the default font does not support them. I have tried several fixes (some of them based on posts to this forum) which all work when I launch the application directly from the command line but all fail when Java Web start is used instead.
1) Passing these parameters from the command line
java -Xmx1g -jar /Users/sschultz/Documents/workspace/core-mcf/build/Pert.jar -Dswing.aatext=true -Dswing.plaf.metal.controlFont=Arial -Dswing.plaf.metal.userFont=Arial
does work. However, I understand that to pass them in the JNLP file they need to be passed as properties like this:
<resources>
<j2se version="1.7" java-vm-args="-Xmx512m"/>
<property name="swing.aatext" value="true"/>
<property name="swing.plaf.metal.controlFont" value="Arial"/>
<property name="swing.plaf.metal.userFont" value="Arial"/>
<jar href="https://.../Pert.jar"/>
</resources>
Furthermore, because they are considered nonsecure properties, the signed JAR file must include a copy of the JNLP file at JNLP-INF/APPLICATION_TEMPLATE.JNLP. Was able to verify that the template file was in fact being found and was passing verification when the application loaded. However, the Arial font was apparently not being used because the Unicode characters failed to render properly.
2) So I attempted to set the default font directly in the application at startup using:
UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Arial", Font.PLAIN, 10));
This works fine when launched from the command line but fails using web start.
3) Next I tried setting the font only for the panel in which I indented to render the unicode text:
Font font = new Font("Arial", Font.PLAIN, 10);
this.reviewScrollPane.setFont(font);
This too works from the command line but fails with web start.
4) Finally, I read a post that suggested that non-default fonts must be supplied as resources in the JAR file launched by Java Web Start so I added Arial.ttf to my JAR and changed the above code to:
Font font = new Font("Arial", Font.PLAIN, 10);
String msg = "Font found";
ClassLoader cl = this.getClass().getClassLoader();
try
{
font = Font.createFont(Font.TRUETYPE_FONT, cl.getResourceAsStream("Arial.ttf"));
font.deriveFont(Font.PLAIN, 10f);
}
catch (FontFormatException | IOException e)
{
System.out.println(msg = "Font Arial not found.");
}
this.reviewScrollPane.setFont(font);
I verified that Arial.ttf does indeed show up in the JAR and, using logging, that it is in fact being found by the call to createResourceAsStream(). Again, unicode characters are rendered correctly when the application is launched from the command line but now when web start is used.
Any help appreciated.