Example usage for javafx.scene.control MenuItem setOnAction

List of usage examples for javafx.scene.control MenuItem setOnAction

Introduction

In this page you can find the example usage for javafx.scene.control MenuItem setOnAction.

Prototype

public final void setOnAction(EventHandler<ActionEvent> value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }/*from  w w w.  j ava 2 s .co  m*/
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    System.out.println(menu.showingProperty());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }//w w  w  .  j a v  a  2  s  . c o m
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    System.out.println(menu.isShowing());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }/*from w w w .  j a  va2  s. c om*/
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.hide();//  w w  w.  j a  v  a  2s .  c o m

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.show();//from w  w  w .jav  a2s.  co m

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.setOnHiding(new EventHandler<Event>() {
        @Override/*from  w w  w.ja  v  a  2  s .co m*/
        public void handle(Event arg0) {
        }
    });
    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.setOnHidden(new EventHandler<Event>() {
        @Override/*from   www  . j  a  va2 s . c  om*/
        public void handle(Event arg0) {
        }
    });
    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.setOnHidden(new EventHandler<Event>() {
        @Override//from   w  ww.j  a v  a 2  s .  c  o  m
        public void handle(Event arg0) {
        }
    });
    System.out.println(menu.getOnHidden());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("title");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    menu.setOnHiding(new EventHandler<Event>() {
        @Override/* ww  w.j ava 2s.c o  m*/
        public void handle(Event arg0) {
        }
    });
    System.out.println(menu.setOnHiding());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

private MenuItem exitMenuItem() {
    MenuItem exitMenuItem = new MenuItem("Exit");
    exitMenuItem.setOnAction(actionEvent -> Platform.exit());

    return exitMenuItem;
}