AWT 组件上的半透明面板
我有一个 AWT 组件(第 3 方库),我需要通过在其上显示半透明面板(在本例中 alpha 为 128)来遮盖它。有什么办法可以做到这一点吗?我查看了使用 Sun 的 AWTUtilities 类的“TransparentPanel”类,但它有一个限制,即无法显示 0 < 的像素。阿尔法< 255. 即使这不是一个很好的解决方案,我只是在寻找一些方法来做到这一点。
I have an AWT component (3rd party library), and I need to mask it by showing a translucent panel over it (alpha of 128 in this case). Is there any way at all to do this? I looked at the "TransparentPanel" class that uses Sun's AWTUtilities class, but that has a limitation of not being able to show pixels with 0 < alpha < 255. Even if it's not a pretty solution, I'm just looking for some way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许带有半透明涂料的 GlassPane 可以解决这个问题。这是一个简单的例子:
Maybe a GlassPane with translucent paint can solve this. Here's a simple example:
据我所知,你不能这样做。更接近的是创建 AWT 组件的屏幕捕获,同时在上面显示 swing 组件,并最终不时刷新屏幕捕获。这意味着本机组件并不真正存在,并且在屏幕捕获模式下无法使用(不响应鼠标单击和按键事件)。
这是 DJ NativeSwing 示例之一在嵌入式 Web 浏览器上覆盖具有 alpha 透明度的 Swing PNG 图像的做法。查看演示:http://djproject.sourceforge.net/ns
As far as I know, you cannot do this. What comes closer is to create a screen capture of the AWT component while a swing component is to be shown above, and eventually refresh the screen capture now and then. That means the native component is not really there and cannot be used while in screen capture mode (does not respond to mouse clicks and key events).
This is what one of DJ NativeSwing example does to overlay a Swing PNG image with alpha transparency above an embedded web browser. Check the demo: http://djproject.sourceforge.net/ns