Java Applet:浏览器中没有抗锯齿字体(但在 AppletViewer 中)
在 AppletViewer 中,我的 Applet 如下所示:
在浏览器中,我的 Applet 如下所示:
如您所见,字体未进行抗锯齿处理。而且背景颜色也不一样。所有文本都被剪切在右侧。
那会是什么?
您也可以自己尝试此处。
从这里我尝试过使用此代码:
System.setProperty("awt.useSystemAAFontSettings","on");
System.setProperty("swing.aatext", "true");
但这只会导致此异常:
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)
In the AppletViewer, my Applet looks like this:
In the browser, my Applet looks like this:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该通过重写
paint
方法来工作,对于每个您想要抗锯齿的组件,如下所示:It should work by overriding the
paint
method like this for each component where you want to have anti-aliasing: