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

A button with setDefaultButton(true) consumes Enter event, even when it is disabled.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7u6
    • fx2.1
    • javafx
    • Windows 7, JavaFX beta 2.1 b13

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

            kwwong Kinsley Wong (Inactive)
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: