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

Menu: setOnAction is not fired

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7, JavaFX 2.1 beta b14

      Description

      See the code below: the ActionEvent on the Menu labeled "SubMenu" is not fired.
      It seems, it is only fired by MenuItems, but not by Menus.

      I have a legitimate use case for this and I hope this isn't by design (because the default action is to show the sub menu).
      I also don't have the ability to use addEventFilter, in case the event is consumed, by the default implementation.


      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      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(args);
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();

              MenuBar menuBar = new MenuBar();

              Menu mainMenu = new Menu("MainMenu");

              menuBar.getMenus().add(mainMenu);

              Menu subMenu = new Menu("SubMenu");
              subMenu.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("SubMenu action does not work");
                  }
              });

              mainMenu.getItems().add(subMenu);

              MenuItem subMenuItem = new MenuItem("SubMenuItem");

              subMenu.getItems().add(subMenuItem);

              subMenuItem.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("SubMenuItem action");
                  }
              });

              root.getChildren().add(menuBar);

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

        Attachments

          Activity

            People

            • Assignee:
              psomashe Parvathi Somashekar (Inactive)
              Reporter:
              cschudtjfx Christian Schudt (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Imported: