To disable a button in a Java Swing application, you can use the setEnabled
method of the AbstractButton
class.
Here's an example of how to disable a button in a Java Swing application:
JButton button = new JButton("Click me"); button.setEnabled(false);
In this example, we're creating a new JButton
object with the label "Click me" and then using the setEnabled
method to disable the button. The button will no longer be clickable and will appear grayed out.
You can also enable the button again by calling the setEnabled
method with a true
argument:
button.setEnabled(true);
This will re-enable the button and make it clickable again.
You can find more information about the JButton
class and how to use it in Java Swing applications in the Java documentation.