如何使用秋千创建可扩展面板? [英] How to create expandable panels using swing?

查看:62
本文介绍了如何使用秋千创建可扩展面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个展开和/或折叠面板的列表,如这张图片所示:

I would like to create a list of expandand/collapse panels, like on this image:

我还没有找到任何摆动组件,所以我开始创建类似的东西. 我试图将一个按钮放在另一个按钮下面,以填充可用的宽度,但实际上不起作用.我只能看到最后添加的一个.

I haven't found any swing component for this, so I began to create something like this. I tried to put buttons one under the other, which fill the available width, but doesn't really works. I can only see the last added one.

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    panel.add(new JButton("Delphi Projects"), BorderLayout.NORTH);
    panel.add(new JPanel(), BorderLayout.NORTH); // hidden panel
    panel.add(new JButton("Delphi Projects | Delphi Files"), BorderLayout.NORTH);
    panel.add(new JPanel(), BorderLayout.NORTH); // hidden panel
    panel.add(new JButton("Other Files"), BorderLayout.NORTH);
    panel.add(new JPanel(), BorderLayout.NORTH); // hidden panel
    panel.add(new JButton("C++ Builder Projects | C++ Builder Files"), BorderLayout.NORTH);
    panel.add(new JPanel(), BorderLayout.NORTH); // hidden panel

    JScrollPane scroll = new JScrollPane(panel);

推荐答案

您可以从

You can take a look to JXTaskPaneContainer and JXTaskPane from SwingX project which have these advantages:

  • They are components just like a JPanel is so no extra effort is required to work with them.
  • Unlike accordions you can have more than one panel expanded at any time.
  • They have a cool and smooth effect on collapsing/expanding events.
  • Unlike trees/tree tables you don't have to mess with either TreeModel nor TreeTableModel at all. Also trees and tree tables are components intended to show data in a hierarhical form, not to add components into it.

如果您不喜欢任务窗格并想自己实现某些功能,则可以使用JXCollapsiblePane(在SwingX API中也可以使用).

If you don't like task panes and want to implement something on your own then you have JXCollapsiblePane (also available in SwingX API).

检查 SwingLabs演示,以获取完整的SwingX组件演示.

Check SwingLabs Demos for a complete set of SwingX components demo.

这篇关于如何使用秋千创建可扩展面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆