A button with setDefaultButton(true) consumes Enter event, even when it is disabled.
I feel this is incorrect behavior. If I (as a developer) disable a button I want to prevent the user to use it (either by click or by keyboard).
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
Button button = new Button("close");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
stage.close();
}
});
button.setDefaultButton(true);
button.setDisable(true);
root.getChildren().addAll(button);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
I feel this is incorrect behavior. If I (as a developer) disable a button I want to prevent the user to use it (either by click or by keyboard).
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
Button button = new Button("close");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
stage.close();
}
});
button.setDefaultButton(true);
button.setDisable(true);
root.getChildren().addAll(button);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
- duplicates
-
JDK-8126318 Default Button gets invoke even if it is disable
- Closed