Detecting mouse click on JPanel even when the click is on the panel's child
My code has a JPanel that contains a JTextPane that covers most of the JPanel. I would like to detect a mouse click if the event occur开发者_运维百科s anywhere in the panel, but the JTextPane blocks the event, unless I register a listener to it. Is there some easy way to observe the event without adding in listeners for every child?
You can use a Global Event Listener to listen for the mouse events.
You can use:
SwingUtilities.isDescendingFrom(...);
to help determine if the component that generated the event is a child of the panel.
精彩评论