-
Bug
-
Resolution: Fixed
-
P3
-
7u6
If I disable a button, I am still able to fire that button. However, my expectation is, that a disabled button cannot be fired. A user cannot use it anymore and a developer shouldn't be able to use it either.
Is it possible to include a simple
if (!getDisabled) in the fire method?
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp4 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
final Button button = new Button();
button.setDisable(true);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
System.out.println("Fired!");
}
});
TextField textField = new TextField();
textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent keyEvent) {
if (keyEvent.getCode().equals(KeyCode.ENTER)) {
button.fire();
}
}
});
root.getChildren().addAll(button, textField);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
Is it possible to include a simple
if (!getDisabled) in the fire method?
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp4 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
final Button button = new Button();
button.setDisable(true);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
System.out.println("Fired!");
}
});
TextField textField = new TextField();
textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent keyEvent) {
if (keyEvent.getCode().equals(KeyCode.ENTER)) {
button.fire();
}
}
});
root.getChildren().addAll(button, textField);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}