I have an extensive Gui with many components in it. There is a updateEnable() methods that updates the enable state of all the components based on some configuration.
I basically first set their enable state to true and then disable some of them (based on the configuration):
private void updateEnable() {
enableAllRec(panel, true);
// disable some components
}
private void enableAllRec(Container root, boolean b) {
if (root == null) return;
for (Component c : root.getComponents()) {
c.setEnabled(b);
if (c instanceof Container) enableAllRec((Container) c, b);
}
}
The reason I do it like that is that some of the components are not stored as member variables and I don't have access to them. They however can change their state because I initialized some of them like this (for example):
final JLabel exampleLabel = new JLabel("yoink");
final JCheckBox exampleCheckBox = new JCheckBox("boing");
exampleCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
exampleLabel.setEnable(exampleCheckBox.isSelected());
}
});
Now my problem is the following: When I call updateEnable(), some of the (stored) Components may flicker because they are enabled and then disabled again after some time. I would like to prevent that. My idea is to somehow prevent the GUI from refreshing until the very end of updateEnable() and then perform an updateUI(). But this is not very elegant AND I have no idea how to prevent the GUI from updating.
Am I missing a very elegant alternative solution for this problem?
Thanks a lot, Stefan