JTable onchange 事件

发布于 2024-08-14 12:52:43 字数 155 浏览 2 评论 0原文

有什么方法可以检测 JTable 中的单元格选择更改吗?我找到了使用 ListSelectionListener 检测行更改的文档,但在更改同一行上的选择时它不起作用。我正在使用 JTable 来呈现一个简单的时间表。

也许我应该使用不同的组件?

Is there any way to detect a cell selection change in a JTable? I've found documentation for detecting a row change using ListSelectionListener but it doesn't seam to work when changing selection on the same row. I'm using JTable to render a simple schedule.

Maybe I should use a different component?

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

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

发布评论

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

评论(1

千柳 2024-08-21 12:52:43

不,显示表格数据的正确组件是 JTable。

您想要向表下方的 TableModel 添加一个侦听器。每当数据发生变化时,就会触发事件。毫不奇怪,您可以通过调用 getTableModel() 从 JTable 中获取它。


更新

哦等等,我想我误解了你的意思。您对数据更改不感兴趣,但对列选择更改感兴趣。

JTable 有一个名为columnSelectionChanged 的方法;它的文档说它是由 TableColumnModelListener 调用的,这让我相信您想要做的是 getColumnModel() 并使用 addColumnModelListener()监听列选择变化的方法。

No, the right component for showing tabular data is JTable.

You want to add a listener to the TableModel that's underneath the table. That will fire off events whenever data changes. You get it out of JTable, unsurprisingly enough, by calling getTableModel().


Update

Oh wait, I think I misunderstood you. You're not interested in data changes but column selection changes.

JTable has a method called columnSelectionChanged; its documentation says it's called by TableColumnModelListener, which leads me to believe that what you want to do is getColumnModel() and use the addColumnModelListener() method of that to listen for column selection changes.

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