隐藏 JTable 中的列
我们如何显示/隐藏 JTable 中的某些列?
How can we show/hide some columns in JTable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我们如何显示/隐藏 JTable 中的某些列?
How can we show/hide some columns in JTable?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
我推荐 SwingX 项目中的 JXTable,在视图中隐藏列非常简单:
JXTable 还提供了一个列控件(右上角的菜单),用户可以自己隐藏/显示列。
I recommend JXTable from the SwingX project, hiding columns in the view is very easy:
JXTable also provides a column control(menu in top-right corner) where user by them selfs can hide/show columns.
当按照 Uhlen 的建议使用 SwingX 项目中的 JXTable 时,
最好使用
table.getColumnExt("columnName").setVisible(true);
table.getColumnExt("columnName").setVisible(false);
使用
getColumnExt(index)
时的索引是视图中的列索引(即可见)一旦将列设置为不可见,您就无法通过
getColumnExt(index)
访问它When using JXTable from the SwingX project, as suggested by Uhlen,
It's better to use
table.getColumnExt("columnName").setVisible(true);
table.getColumnExt("columnName").setVisible(false);
the index when using
getColumnExt(index)
is the column index that is in the view (i.e.visible)Once you set a column invisible, you can't access to it by
getColumnExt(index)
您不必像 codeGuru 中所示的那样为每个单元格调用循环遍历列表,而是可以通过设置零宽度和设置可编辑/不可编辑来更改 columnModel 以切换列可见性。该 wat 默认处理会跳过该列。
Instead of having to loop through the list for every cell call as shown at codeGuru, you could change the columnModel to switch the column-visibility by setting from/to zero-width and setting editable/noneditable. That wat default handling skips over that column.
您可以在 codeguru 找到示例:
不要忘记谷歌是你最好的朋友......
You can find a sample at codeguru:
Don't forget that google is your best friend ...