JTable:如何在运行时选择列
我的表中有太多列,无法一次显示所有列,并且想让用户更改哪些列可见。我该怎么做?
注意:让应用程序在运行时选择列很容易。我要问的是要添加哪些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您可以导入一些外部库,您可以看看
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.
表格列管理器允许用户右键单击表标题可控制哪些列可见。
Table Column Manager allows the user to right click on the table header to control which columns are visible.
没有标准方法,但是您可以执行以下操作:
或者:找到一个可以执行此操作的自定义组件。可能已经有一些东西了:像 JIDE 的组件库这样的项目将是一个不错的选择。
There isn't a standard way, however what you could do is something like this:
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.
使用 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).
当用户右键单击标题时,显示一个包含可能列的弹出菜单,或者实现一个带有复选框列表的小(轻)弹出对话框,用于选择可见列。可以通过右键单击、单击工具栏按钮或从工具栏菜单打开该对话框。
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.