Java Applet:浏览器中没有抗锯齿字体(但在AppletViewer中)

在AppletViewer中,我的Applet看起来像这样: 截图AppletViewer

在浏览器中,我的Applet看起来像这样: 截图浏览器

如您所见,字体不是抗锯齿的。 背景颜色也不同。 并且所有文本都在右侧切割。

那可能是什么?

你也可以在这里试试吧。


从这里我试着使用这段代码:

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

但这只会导致以下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) 

它应该通过覆盖你想要消除锯齿的每个组件的paint方法来工作:

 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); }