英文:
Smooth round corners of JPanel
问题
我制作了一个自定义的Windows桌面应用程序,目前一切看起来都不错,但我希望它尽可能地好。我在任务栏中使用的JPanel
具有圆角,但当您仔细看时,边缘并不模糊或平滑。有没有一种简单的方法来修复这个问题?
这是任务栏的屏幕截图:
英文:
I made a custom Windows desktop app and for now everything looked good but I want it to be as good as possible. The JPanel
I used in the dock has round corners but when you look closer, the edges are not blurred or smooth. Is there some easy way to fix that?
Here is a screenshot of the dock:
答案1
得分: 1
很遗憾,Swing 不适用于高 DPI 显示。
这里讨论了一些尝试的方法hiDPI look and feel,但是关于在 Windows 上运行应用程序,你可以始终更改兼容性设置,因为 Windows 默认会假定应用程序是 DPI 感知的,不会尝试缩放它(右键单击桌面图标,然后在兼容性选项卡上更改高 DPI 设置)。
正如@weisj建议的那样,升级到 jdk 9+ 可能会解决这个问题,但随后的评论中已经发现了一个 bug。我查阅了关于此的 openjdk 注释JEP263 HiDPI graphics,看起来已经完成了支持现代显示器的工作。当然,这会给用户带来额外的工作,因此可能不太实际。一如既往,这取决于实际结果如何。
英文:
Unfortunately it's problematic as Swing is not designed for high DPI aware displays.
Here is a discussion of approaches to try hiDPI look and feel, however as far as running the app on Windows you can always alter the compatibility settings as Windows by default will assume the app is DPI aware and will not attempt to scale it (right click on the desktop icon, then on the compatibility tab change high DPI settings.)
As @weisj has suggested updating to jdk 9+ may fix this, however subsequently a bug has been identified per the comments below. I looked up the openjdk notes on this JEP263 HiDPI graphics and it looks as if the work has been done to support modern displays. That does of course impose additional work for the users so may not be practical. As always it depends what the actual results look like.
答案2
得分: 0
在 paintComponent()
中激活抗锯齿并绘制你的 RoundRectangle2D。
示例:
Swing 中的抗锯齿
英文:
Activate antialiasing in paintComponent() and draw your RoundRectangle2D.
Example:
Antialiasing in Swing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论