Weird behavior of a MouseListener added to a JTable
I've hooked up a mouse listener to a JTable to call some stuff when mouse c开发者_Go百科ursor leaves table's bounds. However, mouseExited() method is also called when the mouse cursor is leaving individual cells of a table. Is it some strange quirk in my code or a bug in Swing?
EDIT: I didn't mention that my table is a subclass of a JTable and not a standard JTable
Sounds normal to me if you're not checking for event.getSource() == myTable
Adding mouse listeners to PL&F-heavy components is not a great idea. They often have subcomponents which spoil the party. Mouse events are different from other events in that they bubble up the component hierarchy until they hit a component with a mouse listener (so adding a mouse listener is an intrusive operation). JTable in particular uses renderer to stamp each cell as well as editor components.
(Also subclass compnents such as JTable, or other classes such as Thread, is generally a bad idea.)
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论