How to Enabling and Disabling Components in Java

By default, all components are enabled. However, we may wish to disable a component. A disabled component cannot respond when clicked by the user. Having disabled a component, as a result of user actions we may wish to enable it again. Enabling and disabling are performed by the javax.swing.JComponent.setEnabled(boolean) method. For example, the statement

button2.setEnabled(false);

will disable the JButton object button2. Some disabled components, such as buttons, will take on a different (usually fainter) appearance from their enabled counterparts.

No comments:

Post a Comment