I have a LayeredPane with two JPanels, all in a JFrame. Both JPanels 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).

1 Answer
1

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.

"transparency does not play into any of this at all except as a distraction" Well, that and making it harder to locate the panel to click in the first place. ;) IMO most transparency increases the eye-candy factor while decreasing the usability.
–
Andrew ThompsonSep 24 '11 at 6:37