禁用 JTable 中的单列拖动

发布于 2024-08-18 17:29:27 字数 60 浏览 2 评论 0原文

我应该如何禁止在 JTable 中拖动单个列?我想允许拖动其他列,但只允许拖动第一列(索引为 0)。谢谢。

How should I disable just a single column from dragging in JTable? I want to allow other columns from dragging but just the first column (indexed at 0). Thanks.

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

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

发布评论

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

评论(2

违心° 2024-08-25 17:29:27

您应该能够创建自己的 TableColumnModel (扩展 DefaultTableColumnModel) 并覆盖 moveColumn 仅在允许列时调用 super.moveColumn被拖拽。

编辑:看看首先是这篇文章

You should be able to create your own TableColumnModel (extend DefaultTableColumnModel) and to override moveColumn to only call super.moveColumn when the column is allowed to be dragged.

EDIT: Have a look at this post first.

凑诗 2024-08-25 17:29:27

对你来说不太对劲……在另一个博客上发现,

yourJTable.getTableHeader().setReorderingAllowed(false)

这使得整个表不会重新排序列,这正是我所需要的。探索Override才是正确路线

Not quite on point for you ....found on another blog

yourJTable.getTableHeader().setReorderingAllowed(false)

this gets the entire table not to reorder columns which is what I needed. Exploring the Override is the correct route

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