简体   繁体   English

JPanel的平滑圆角

[英]Smooth round corners of JPanel

I made a custom Windows desktop app and for now everything looked good but I want it to be as good as possible.我制作了一个定制的 Windows 桌面应用程序,现在一切看起来都不错,但我希望它尽可能好。 The JPanel I used in the dock has round corners but when you look closer, the edges are not blurred or smooth.我在 Dock 中使用的JPanel有圆角,但当你仔细观察时,边缘并不模糊或平滑。 Is there some easy way to fix that?有什么简单的方法可以解决这个问题吗?

Here is a screenshot of the dock:这是码头的屏幕截图:

在此处输入图像描述

Unfortunately it's problematic as Swing is not designed for high DPI aware displays.不幸的是,这是有问题的,因为 Swing 不是为高 DPI 感知显示器而设计的。

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.)这是尝试hiDPI 外观和感觉的方法的讨论,但是就在 Windows 上运行应用程序而言,您始终可以更改兼容性设置,因为 Windows 默认情况下将假定应用程序是 DPI 感知的并且不会尝试缩放它(右键单击在桌面图标上,然后在兼容性选项卡上更改高 DPI 设置。)

As @weisj has suggested updating to jdk 9+ may fix this, however subsequently a bug has been identified per the comments below.正如@weisj 建议更新到 jdk 9+ 可能会解决此问题,但随后根据以下评论确定了一个错误。 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.我在这个JEP263 HiDPI 图形上查找了 openjdk 注释,看起来好像已经完成了支持现代显示器的工作。 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.与往常一样,这取决于实际结果的样子。

Activate antialiasing in paintComponent() and draw your RoundRectangle2D.在paintComponent() 中激活抗锯齿并绘制您的RoundRectangle2D。

Example: Antialiasing in Swing示例: Swing 中的抗锯齿

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM