JTable:如何在运行时选择列

发布于 2024-09-08 16:59:00 字数 126 浏览 1 评论 0原文

我的表中有太多列,无法一次显示所有列,并且想让用户更改哪些列可见。我该怎么做?

注意:让应用程序在运行时选择列很容易。我要问的是要添加哪些 UI 元素以允许用户在运行时隐藏/取消隐藏列。

I have too many columns in a table to display them all at once, and would like to let the user change which columns are visible. How can I do this?

note: It is easy to make the application select columns at runtime. What I am asking is what UI element(s) to add to allow the user to hide/unhide columns at runtime.

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

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

发布评论

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

评论(5

作妖 2024-09-15 16:59:00

如果您可以导入一些外部库,您可以看看
http://swinglabs.org/docs/components/JXTable/tutorial.jsp 支持此类运行时修改。

If you can import some external libraries, you could have a look to
http://swinglabs.org/docs/components/JXTable/tutorial.jsp which supports such runtime modifications.

尬尬 2024-09-15 16:59:00

表格列管理器允许用户右键单击表标题可控制哪些列可见。

Table Column Manager allows the user to right click on the table header to control which columns are visible.

谜泪 2024-09-15 16:59:00

没有标准方法,但是您可以执行以下操作:

  1. 使用自定义表头呈现组件在列标题上安装其他操作/UI(例如通过复选框的上下文菜单)
  2. 添加您需要的自定义模型可以重新配置以根据用户通过列标题上的附加操作选择的内容来显示不同的项目
  3. 进行事件接线/管道连接。

或者:找到一个可以执行此操作的自定义组件。可能已经有一些东西了:像 JIDE 的组件库这样的项目将是一个不错的选择。

There isn't a standard way, however what you could do is something like this:

  1. Use a custom table header render component to install additional actions/UI on the column headers (e.g. through a context menu of checkboxes)
  2. Add a custom model which you can re-configure to display different items depending on what the user selected through additional actions on the column headers
  3. Do the event wiring/plumbing.

Alternatively: find a custom component that does this. There probably is something out there already: projects like the component library from JIDE would be a good place to look.

半世蒼涼 2024-09-15 16:59:00

使用 TableModel.addColumn(TableColumn) 和 TableModel.removeColumn(TableColumn) 方法动态显示/隐藏列。

您可以将该调用附加到任何其他 GUI 组件(例如,制作带有几个复选框的 JPanel 或 JTable)。

Use TableModel.addColumn(TableColumn) and TableModel.removeColumn(TableColumn) methods to show/hide columns on-the-fly.

You can attach that calls to any other GUI components (for example, make a JPanel or a JTable with a few checkboxes).

醉梦枕江山 2024-09-15 16:59:00

当用户右键单击标题时,显示一个包含可能列的弹出菜单,或者实现一个带有复选框列表的小(轻)弹出对话框,用于选择可见列。可以通过右键单击、单击工具栏按钮或从工具栏菜单打开该对话框。

Either display a popup menu with the possible columns when user right-clicks the header or implement a small (and light) popup dialog with a checkbox list for selecting the visible columns. The dialog can be opened by right-clicking, by clicking a toolbar button or from a toolbar menu.

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