1

In the AppletViewer, my Applet looks like this: screenshot AppletViewer

In the browser, my Applet looks like this: screenshot browser

As you can see, the font is not antialiased. Also the background color is different. And all the text is cutted on the right side.

What could that be?

You can also try it yourself here.


From here I tried to use this code:

System.setProperty("awt.useSystemAAFontSettings","on");
System.setProperty("swing.aatext", "true");

But that results only in this exception:

java.security.AccessControlException: access denied (java.util.PropertyPermission awt.useSystemAAFontSettings write)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.System.setProperty(System.java:742)
    at applets.Termumformungen$in$der$Technik_08_Ethanolloesungen.Applet.init(Applet.java:51)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1640)
    at java.lang.Thread.run(Thread.java:680)
Exception: java.security.AccessControlException: access denied (java.util.PropertyPermission awt.useSystemAAFontSettings write)
Community
  • 1
  • 1
Albert
  • 65,406
  • 61
  • 242
  • 386
  • Here I get only *Could not initialize applet.* error messages. (OpenJDK 1.6.0_20 (IcedTea6 1.9.7), Firefox, on OpenSUSE 64 bit.) – Paŭlo Ebermann Mar 18 '11 at 16:16
  • Opera the same. In the appletviewer it looks good (gray), but it does not actually shows what you have in the screenshot. – Paŭlo Ebermann Mar 18 '11 at 16:19
  • @Paŭlo: Uh, interesting... Do you get some error? What does the error console say? There must be some output somewhere saying why it can't initialize the applet... :) – Albert Mar 18 '11 at 16:55
  • The error messages (and stack traces) appear on `~/.icedteaplugin/java.stderr` (there is no Java console for the IcedTea-plugin, yet). There are quite some messages, but I'm not really sure how much are for each applet, since there are four or five on your page. If you made a page with only one applet, I could test more easily. The stack traces do not mention anything in your code, though. (It may have to do something with the spaces in your directory path.) And it is surely not related to your antialiasing question, I think. – Paŭlo Ebermann Mar 18 '11 at 17:00
  • As a way to hunt your antialiasing problem: Could you try to find out which Java version your browser is using? Compare this to the output of `appletviewer -J-version`. – Paŭlo Ebermann Mar 18 '11 at 17:02
  • @Paŭlo: It seems to be the same version. I also only have one version installed at all. – Albert Mar 19 '11 at 16:25

1 Answers1

2

It should work by overriding the paint method like this for each component where you want to have anti-aliasing:

static void activateAntiAliasing(Graphics g) {
    try {
        Graphics2D g2d = (Graphics2D)g;

        // for antialiasing geometric shapes
        g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
                              RenderingHints.VALUE_ANTIALIAS_ON );

        // for antialiasing text
        g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING,
                              RenderingHints.VALUE_TEXT_ANTIALIAS_ON );

        // to go for quality over speed
        g2d.setRenderingHint( RenderingHints.KEY_RENDERING,
                              RenderingHints.VALUE_RENDER_QUALITY );
    }
    catch(ClassCastException ignored) {}
}

@Override public void paint(final Graphics g) {
    activateAntiAliasing(g);
    super.paint(g);
}
Albert
  • 65,406
  • 61
  • 242
  • 386