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

Disabled Controls can still be activated by Mnemonic

XMLWordPrintable

      If I use Mnemonics for my Controls, the action event of that control is still fired, when I use that mnemonic (keyboard input), although the control is disabled.

      As a developer, if I disable my controls, I don't want the user to be able to use that control, no matter if by mouse or by keyboard. The action event should not fire on disabled controls.

      Here is a sample (e.g. press ALT + T and see that output is still written).

      This is probably an issue in javafx.scene.control.Labeled base class.


      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.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TestApp3 extends Application {


          public static void main(String[] args) throws Exception {
              launch();
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();

              Button button = new Button("_Test");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("Button action");
                  }
              });
              button.setDisable(true);

              MenuBar menuBar = new MenuBar();

              Menu menu = new Menu("_Menu");

              MenuItem item = new MenuItem("_Item");
              item.setDisable(true);
              item.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("Item activated");
                  }
              });
              menu.getItems().add(item);

              menuBar.getMenus().add(menu);


              root.getChildren().add(menuBar);
              root.getChildren().add(button);

              Scene scene = new Scene(root);
              stage.setScene(scene);
              stage.show();
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported: