开发者

Detecting mouse click on JPanel even when the click is on the panel's child

开发者 https://www.devze.com 2023-03-24 05:35 出处:网络
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 t

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消