I'm creating a ToolBar
with one JButton
and some JCheckBox
s to hide or show columns from a JTable
.
The JButton
main purpose is to once clicked reset all the other JCheckBox
in the ToolBar
to either all checked or all unchecked. Actually I pretend to once reset is clicked to check all of them.
I can create them and place them, no problems here.
My problem is how to make the JButton once clicked to reset all the JCheckBox in the ToolBar
.
Here is my code, where I create them and add the Action
.
final JToolBar toolBarTop = new JToolBar();
// The Reset Button
toolBarTop.add(new JButton(new AbstractAction("Reset") {
@Override
public void actionPerformed(ActionEvent e) {
columnModel.setAllColumnsVisible();
}
}));
// Create a JCheckBox for each column
for(int i = 0; i < labelsCheckBox.size(); i++)
{
final int index = i;
toolBarTop.add(new JCheckBox(new AbstractAction(labelsCheckBox.get(i)) {
@Override
public void actionPerformed(ActionEvent e) {
TableColumn column = columnModel.getColumnByModelIndex(index);
boolean visible = columnModel.isColumnVisible(column);
columnModel.setColumnVisible(column, !visible);
}
}));
}