Transparent AWT component, possible?

折月煮酒 提交于 2019-12-24 21:13:39

问题


I'm in the need of a translucent AWT component/container to be placed on top of other components to receive the mouse events.

The problem here is to create a translucent component. My investigation so far showed that Swing has the possiblity to do setOpaque(false) on e.g. a JPanel. Is there something similiar for AWT?

The idea is to make a ScrollPane scrollable by simply clicking somewhere and moving the mouse around. Thats why I need a transparent component to place it above all other components.

Long story short, I need a translucent component, no matter which one, to place on top of other elements to receive the mouse events.

Thanks in advance


回答1:


AFAIK not possible correctly for prehistoric AWT Container and Components you can to try that with changing this code from Swing to the AWT, Translucency is supported for Swing JComponents only




回答2:


The JNA project provides some utilities for making AWT components translucent. There's a WebStart demo of the functionality. The window transparency utilities are in platform.jar, which augments the base jna.jar.

However, if all you want to do is trap mouse events, you should look into the different layers that are already built into a JFrame. The component already has a concept of layers via JLayeredPane, and you can fairly easily use a JPanel as a glass pane which sits above all other components to filter events.



来源:https://stackoverflow.com/questions/9290581/transparent-awt-component-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!