简体   繁体   English

Java 高效覆盖透明组件

[英]Java efficient overlay over transparent components

I have a custom JComponent that performs come complicated painting.我有一个自定义的 JComponent 来执行复杂的绘画。 It is set to non-opaque so that the background of its parent shows through the parts it does not paint.它设置为不透明,以便其父级的背景通过它不绘制的部分显示。

I need an mouse overlay (a simple shape) that follows the mouse.我需要一个跟随鼠标的鼠标叠加层(一个简单的形状)。 It really shouldn't need to repaint the component below it every time the mouse moves.每次鼠标移动时,它真的不需要重新绘制它下面的组件。 So I'm thinking to buffer the JComponent but because it's non-opaque, calling.paint(buffer) will not paint the background of the parent.所以我正在考虑缓冲 JComponent 但因为它是非透明的,所以 call.paint(buffer) 不会绘制父级的背景。

Any ideas?有任何想法吗?

Thanks in advance.提前致谢。

I have a custom JComponent that performs come complicated painting.我有一个自定义的 JComponent 来执行复杂的绘画。

Maybe your complication painting can be done to a BufferedImage.也许你的复杂绘制可以对 BufferedImage 进行。 Then the component just draws the image so you don't have to invoke the complicated code every time.然后组件只绘制图像,因此您不必每次都调用复杂的代码。 The image would be recreated whenever properties affecting the image are changed.每当更改影响图像的属性时,都会重新创建图像。

May me you can use JWindow.愿我你可以使用JWindow。 Just make it visible and change position of the JWindow on mouse move?只需让它可见并在鼠标移动时更改 JWindow 的 position?

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

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