How to disable all components in a panel(JPanel actually)

How to iterate all the components in a panel, and then operate on them? The following code can work as a reference or a clue of solving likewise problems.
public Container disableAllComponentsInPSIPPanel(Container container)
	{
		Container result = null;
		for(int i = 0; i < container.getComponentCount(); i++)
		{
			Component component = container.getComponent(i);
			if(component instanceof JFormattedTextField)
			{
				component.setEnabled(false);
			}
			if(component instanceof JCheckBox)
			{
				component.setEnabled(false);
			}
			if(component instanceof WideComboBox)
			{
				component.setEnabled(false);
				// ((WideComboBox)component).getSelectedItem();
			}
			if(component instanceof Container)
			{
				disableAllComponentsInPSIPPanel((Container) component);
			}
		}
		result = container;
		return result;
	}



When using this strip of code, you need just put in a JPanel instance. It's not so complex, right?



你可能感兴趣的:(How to disable all components in a panel(JPanel actually))