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

[SplitMenuButton] onAction event handler is not called

    Details

      Description

      run attached sample:

      import javafx.application.Application;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.SplitMenuButton;
      import javafx.stage.Stage;

      public class SplitMenuButtonBug extends Application {

      SplitMenuButton testSplitMenuButton;
          
          @Override
          public void start(Stage stage) {
              ObservableList<MenuItem> testMenuItems = javafx.collections.FXCollections.<MenuItem>observableArrayList();
              for (int indx = 1; indx <= 5; indx++) {
                  MenuItem mi = new MenuItem();
                  mi.setText("Test MenuItem -" + indx);
                  mi.setOnAction(new EventHandler<ActionEvent>() {

                      @Override
                      public void handle(ActionEvent e) {
                          System.out.println(e.getTarget());
                      }
                  });
                  testMenuItems.add(mi);
              }

              testSplitMenuButton = new SplitMenuButton();
              testSplitMenuButton.getItems().clear();
              testSplitMenuButton.getItems().addAll(testMenuItems);
              testSplitMenuButton.setText("Test Menu");
              
              testSplitMenuButton.setOnAction(new EventHandler<ActionEvent>(){

                  @Override
                  public void handle(ActionEvent t) { //Is not called.
                      System.out.println("catch");
                      System.out.println(t);
                  }
              });

              Scene scene = new Scene(new Group(testSplitMenuButton), 300, 300);
              stage.setScene(scene);
              stage.show();
          }

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


      I expect, that pressing on split menu button, I see "catch" at least.

        Attachments

          Activity

            People

            • Assignee:
              leifs Leif Samuelsson (Inactive)
              Reporter:
              akirov Alexander Kirov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: