1

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).

Cajunluke
  • 3,103
  • 28
  • 28
wchargin
  • 15,589
  • 12
  • 71
  • 110

1 Answers1

4

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 1
    *"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 Thompson Sep 24 '11 at 06:37