-
Bug
-
Resolution: Fixed
-
P3
-
fx2.1
-
Windows 7, JavaFX 2.1 beta b14
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();
}
}
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();
}
}