Reputation: 16037
I have a LayeredPane
with two JPanel
s, all in a JFrame
. Both JPanel
s are set to be transparent with setOpaque(false)
. However, I would like to capture mouse events on the (top, if it makes a difference) transparent panel. Is this possible, or should I just do it from the underlying JFrame
? (It would definitely work to capture from the JFrame
; it just makes more logical sense to capture the events from the transparent frame).
Upvotes: 1
Views: 1292
Reputation: 285403
You can capture mouse events on whichever JPanel has a MouseListener attached to it, and is not encumbered by components that also have MouseListeners added, and who are laying on or above the original JPanel. This looks like a situation perfect for creating a small test class that is the most simple of GUI's, that has none of the bells and whistles of your GUI, but that illustrates your problem and hopeful solution.
Also, please know that the transparency does not play into any of this at all except as a distraction.
Upvotes: 4