Collapse/Expand multiple GroupBox'es at a time

If I have multiple collapsable GroupBox elements on a page, how can I collapse/expand multiple boxes at a time? E.g. a button a to collapse all GropuBox’es at the same time.


First of all you have to collect your GroupBoxes in some collection (e.g. List).

List<GroupBoxLayout> groupBoxes = collectGroupBoxes();

Then you should set action to the button. Inside of this action you should iterate over all your elements and collapse or expand them:

expandButton.setAction(new AbstractAction("expandGroupBoxes") {
    public void actionPerform(Component component) {
        for (GroupBoxLayout groupBox : groupBoxes) {
            // expand GroupBox if it is collapsed, or collapse if expanded

Awesome, thanks Daniil! This works a treat.