Ad Code

Responsive Advertisement

JAVA & Netbeans Tutorial: Enable and Disable jButton in Java

Enable and Disable jButton in java is use specially if you are working with a Save, Update, Delete function of your Java with Netbeans program. Some programmer want's to disable button in form load event specially the update and delete jButton to avoid the user adding duplicate entries. 



To enable and disable jButton is so simple because it is uses a true and false option, for example if true the button is enable and if false the button is disable. Try to check the code below.

btn_Save.setEnabled(true);btn_Update.setEnabled(false);

The bold part of the code is our jButton variable name. If you understand the code, the save button is enable and the update button is disable. Our goal is to add that button function on form load event, meaning the two jButtons automatically set their own functions.

To do that, look at your code and try to find the your main class code, usually it is bundled with initComponents();. Try to check the code below.

public DoctorRegistration() {        initComponents();        btn_Save.setEnabled(true);
        btn_Update.setEnabled(false);
        btn_Delete.setEnabled(false);
        btn_Update.setEnabled(false);        btn_Delete.setEnabled(false);        }
The bold code is your new code for disabling and enabling the jButton. I am using Netbeans IDE in building this program.

Post a Comment

0 Comments

Close Menu