I've hooked up a mouse listener to a JTable to call some stuff when mouse cursor 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?
当鼠标光标离开表的边界时,我将一个鼠标监听器连接到一个JTable中,以调用一些东西。但是,当鼠标指针离开表的单个单元时,还会调用mouseExited()方法。我的代码中有奇怪的怪癖还是Swing中的bug ?
EDIT: I didn't mention that my table is a subclass of a JTable and not a standard JTable
编辑:我没有提到我的表是JTable的子类,而不是标准的JTable
2 个解决方案
#1
1
Sounds normal to me if you're not checking for event.getSource() == myTable
如果您不检查event.getSource() = myTable,这对我来说听起来很正常
#2
0
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.
将鼠标监听器添加到pl&f重型组件并不是个好主意。他们经常有破坏聚会的小部件。鼠标事件与其他事件的不同之处在于,它们向上冒泡组件层次结构,直到用鼠标监听器击中组件(因此添加鼠标监听器是一种入侵操作)。JTable特别使用渲染器对每个单元格和编辑器组件进行标记。
(Also subclass compnents such as JTable
, or other classes such as Thread
, is generally a bad idea.)
(另外,JTable之类的子类编译器,或者Thread之类的其他类编译器,通常都不是一个好主意。)
#1
1
Sounds normal to me if you're not checking for event.getSource() == myTable
如果您不检查event.getSource() = myTable,这对我来说听起来很正常
#2
0
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.
将鼠标监听器添加到pl&f重型组件并不是个好主意。他们经常有破坏聚会的小部件。鼠标事件与其他事件的不同之处在于,它们向上冒泡组件层次结构,直到用鼠标监听器击中组件(因此添加鼠标监听器是一种入侵操作)。JTable特别使用渲染器对每个单元格和编辑器组件进行标记。
(Also subclass compnents such as JTable
, or other classes such as Thread
, is generally a bad idea.)
(另外,JTable之类的子类编译器,或者Thread之类的其他类编译器,通常都不是一个好主意。)