添加到 JTable 的 MouseListener 的奇怪行为

发布于 2024-09-25 07:47:57 字数 162 浏览 2 评论 0原文

我已将鼠标侦听器连接到 JTable,以便在鼠标光标离开表边界时调用一些内容。但是,当鼠标光标离开表格的各个单元格时,也会调用 mouseExited() 方法。这是我的代码中的一些奇怪的怪癖还是 Swing 中的错误?

编辑:我没有提到我的表是 JTable 的子类,而不是标准 JTable

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?

EDIT: I didn't mention that my table is a subclass of a JTable and not a standard JTable

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫腻 2024-10-02 07:47:57

如果您不检查 event.getSource() == myTable,对我来说听起来很正常

Sounds normal to me if you're not checking for event.getSource() == myTable

路弥 2024-10-02 07:47:57

向 PL&F 密集型组件添加鼠标侦听器并不是一个好主意。他们经常有一些会破坏聚会的子组件。鼠标事件与其他事件的不同之处在于,它们在组件层次结构中向上冒泡,直到它们击中具有鼠标侦听器的组件(因此添加鼠标侦听器是一种侵入性操作)。 JTable 特别使用渲染器来标记每个单元格以及编辑器组件。

(此外,子类组件(例如 JTable)或其他类(例如 Thread)通常也是一个坏主意。)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文