Java swing 渲染优化
据我所知,Java 的本机 swing UI 元素进行了许多渲染优化,因此它的性能更好。也就是说,如果我有一个自定义的 JPanel(也就是说,我已经重写了它的 PaintComponent 方法):
- 渲染优化是否仍然会执行(如我所希望的那样)?
- 我可以手动告诉其父容器何时重新绘制 JPanel 吗?换句话说,我可以冻结 JPanel 的重新渲染,直到明确告知吗?
- 如果是这样(#2),我可以告诉它只重新绘制 JPanel 的特定部分(智能绘画,我认为它被称为......)?
- 最后,重新渲染 JPanel 是否能够处理 JPanel 的透明度、圆角或其他非矩形形状? (我想这意味着它将重新渲染 JPanel 下的元素)
如果没有,是否有替代技术来伪造它? (最好只是我可以阅读的来源/参考的链接)
I understand that Java's native swing UI elements do a number of rendering optimizations so it performs better. That said, if I had a customized JPanel (meaning, I've overriden its paintComponent method):
- Will rendering optimizations be performed still (as I would hope)?
- Can I manually tell its parent container when to repaint the JPanel? Said differently, can I freeze the re-rendering of the JPanel until explicitly told so?
- If so (#2), can I tell it to repaint only a specific portion of the JPanel (smart painting, I think its called...)?
- And finally, will re-rendering the JPanel be able to handle transparency, rounded corners, or other non-rectangular shapes for the JPanel? (meaning it will re-render elements underneath the JPanel, I suppose)
If not, are there alternate techniques for faking it? (preferrably just a link to a source/reference I can read from)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了加快渲染速度,您可以使用 BufferedImage。在图像的图形上渲染一次内容并使用图像而不是渲染所有内容。
要渲染面板的一部分,请使用 Graphics 的 setClip()/getClip() 检查哪个区域必须刷新并仅绘制部分。
要绘制非矩形对象,请使用相同的 setClip 设置必要的形状。
To speed up the rendering you can use BufferedImage. Render your content once on the image's Graphics and use image instead of rendering all the content.
To render portion of panel use Graphics' setClip()/getClip() check which region has to be refreshed and draw only portion.
TO draw non rectangular object use the same setClip setting necessary Shapes.