如何在 Java swing 应用程序中实现 JTable 的展开/折叠特性
在我的应用程序中,我显示了包含大量数据的表列表。窗口可能无法容纳所有表格,我们需要滚动才能看到底部的表格。在这里,我需要表格的展开/折叠性质。用户可以在所有表格中选择他想要查看的表格。这是我的应用程序的示例屏幕截图。
我该怎么做?
In my application I am displaying a list of tables with huge data. All of the tables may not fit in the window, we need to scroll to see the bottom tables. Here I need expand/collapse nature to the tables. User may select which tables he would like to see among all of the tables. This is my sample screen shot of the application.
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试JXTreeTable 或 TreeTable
或者您可以切换jtable的可见性以产生展开/折叠效果。首先,当它可见并且使用选择折叠时,使用
setVisible(false);
并在展开时执行相反的操作。 [不确定这是否有效。]You can try JXTreeTable or TreeTable
or you can switch jtable's visibility to make a expand/collapse effect. First when it is visible and use selects collapse use
setVisible(false);
and do reverse in expand. [Not sure this will work or not.]将面板(panel1、panel2..)添加到“masterlayout”以获得您想要的外观
Add panels(panel1,panel2..) to 'masterlayout' to get your desired look
org .netbeans.swing.outline.Outline
是一个有吸引力的替代方案,正如所讨论的此处和此处。org.netbeans.swing.outline.Outline
is an appealing alternative, as discussed here and here.基于可见性的展开/折叠效果(如 Harry 提出的第二个选项)如果使用 DesignGridLayout:
为
面板
中的每个表格重复上面的代码(在“...
”之后)。在上面的代码中,每个标签都替换为一个复选框,当取消选中该复选框时,会隐藏下面的表格。
您可以查看“动态布局”部分下的 DesignGridLayout 示例应用程序(在主页上以 WebStart 形式提供)。
The expand/collapse effect based on visibility, as proposed as 2nd option by Harry, can be easy to achieve if you use DesignGridLayout:
Repeat the code above (after "
...
") for every table in yourpanel
.With the code above, each label is replace with a checkbox that, when unselected, hides the table underneath.
You can take a look at DesignGridLayout example application (available as WebStart on the home page) under the "Dynamic Layouts" section.
另一种选择是使用 SwingX 的 JXTaskPane
Edited(忘记了代码片段中的 taskPane,永远不要在咖啡之前发布;-)
Yet another alternative is to use SwingX' JXTaskPane
Edited (forgot the taskPane in the snippet, never post before-coffee ;-)