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.
Thanks.
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.
Thanks.
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") {
@Override
public void actionPerform(Component component) {
for (GroupBoxLayout groupBox : groupBoxes) {
// expand GroupBox if it is collapsed, or collapse if expanded
groupBox.setExpanded(!groupBox.isExpanded());
}
}
});
Awesome, thanks Daniil! This works a treat.