Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8125562

Disabled buttons should not fire.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 7u6
    • javafx

      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();
          }
      }

            miflemi Mick Fleming
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: