隐藏 JTable 中的列

发布于 2024-10-01 16:26:26 字数 30 浏览 1 评论 0原文

我们如何显示/隐藏 JTable 中的某些列?

How can we show/hide some columns in JTable?

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

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

发布评论

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

评论(4

素罗衫 2024-10-08 16:26:26

我推荐 SwingX 项目中的 JXTable,在视图中隐藏列非常简单:

table.getColumnExt(index).setVisible(false);

JXTable 还提供了一个列控件(右上角的菜单),用户可以自己隐藏/显示列。

I recommend JXTable from the SwingX project, hiding columns in the view is very easy:

table.getColumnExt(index).setVisible(false);

JXTable also provides a column control(menu in top-right corner) where user by them selfs can hide/show columns.

╰◇生如夏花灿烂 2024-10-08 16:26:26

当按照 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)

多彩岁月 2024-10-08 16:26:26

您不必像 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.

瘫痪情歌 2024-10-08 16:26:26

您可以在 codeguru 找到示例:

不要忘记谷歌是你最好的朋友......

You can find a sample at codeguru:

Don't forget that google is your best friend ...

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