setEnabled(false) into your actionListener. Make the buttons instance variables, do not make them static variables. (Alternatively you could keep the buttons as local variables and assign each of them their own anonymous inner class listener.)
Approach 1:
In UI Dialog box, button as default class called ui-button so focus on it. Create a function that should trigger dialog box in ready that is on page load. Then use jQuery method prop(‘disabled’, true) to disable that button with class ui-button.
You can add a simple ActionListener like this: JButton startButton = new JButton(“Start”); startButton. addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { startButton. setEnabled(false); stopButton.
addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //If Button is clicked, make the button unclickable if(button == (JButton)e. getSource()) { button. setEnabled(false); } } });
How to Disable Buttons using JAVA Applet and AWT
- import java.applet.Applet;
- import java.awt.Button;
- /*
- <applet code=”ButtonDisable” width=100 height=200>
- </applet>
- */
- public class DisableButtons extends Applet {
- public void init() {
In Swing, we can disable a button like this: JButton start = new JButton(“Start”); start. setEnabled(false);
The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the button clickable again.
You can just add “disabled” to your button, and then when the user locks in their answer, enable it again. Additionally, it’s not best practice to split your JavaScript into a bunch of different script tags. Put them all in one place.
You can make use of setEnabled property, button. setEnabled(true); you can set it to false initially , upon validating make it true .
Enabling and Disabling Components
Standard Swing components can be turned on and off by calling the setEnabled() method. When a component such as a JButton or JTextField is disabled, it becomes “ghosted” or “greyed out” and doesn’t respond to user input.