Example usage for javafx.scene.control MenuBar getMenus

List of usage examples for javafx.scene.control MenuBar getMenus

Introduction

In this page you can find the example usage for javafx.scene.control MenuBar getMenus.

Prototype

public final ObservableList<Menu> getMenus() 

Source Link

Document

The menus to show within this MenuBar.

Usage

From source file:net.gazeplay.commons.utils.games.Utils.java

public static MenuBar buildLicence() {
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    String licenseFileAsString = loadLicenseFileAsString(classLoader);

    MenuItem licenseMenuItem = new MenuItem(licenseFileAsString);

    Menu menu = new Menu("GazePlay");
    menu.getItems().add(licenseMenuItem);

    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(menu);
    menuBar.setPrefHeight(40);/*from w  w w . j av a 2  s.c  om*/
    menuBar.setPrefWidth(80);

    return menuBar;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);
    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(fileMenu(), cameraMenu(), alarmMenu());
    root.setTop(menuBar);//from  w  w  w.j  av a 2 s. com
    ContextMenu contextFileMenu = new ContextMenu(exitMenuItem());

    primaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent me) -> {
        if (me.getButton() == MouseButton.SECONDARY || me.isControlDown()) {
            contextFileMenu.show(root, me.getScreenX(), me.getScreenY());
        } else {
            contextFileMenu.hide();
        }
    });
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
    root.getChildren().add(menuBar);//  ww  w .  j av  a 2 s.  c o m

    Menu menu = new Menu("File");
    menuBar.getMenus().add(menu);

    MenuItem newItem = MenuItemBuilder.create().text("New")
            .accelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN))
            .onAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    System.out.println("Ctrl-N");
                }
            }).build();
    menu.getItems().add(newItem);

    MenuItem saveItem = MenuItemBuilder.create().text("Save")
            .accelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN))
            .onAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    System.out.println("Ctrl-S");
                }
            }).build();
    menu.getItems().add(saveItem);

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

    MenuItem exitItem = MenuItemBuilder.create().text("Exit")
            .accelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN))
            .onAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    System.out.println("Ctrl-X");
                }
            }).build();
    menu.getItems().add(exitItem);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu tools = new Menu("Your Menu");
    tools.getItems().add(CheckMenuItemBuilder.create().text("Item 1").selected(true).build());

    tools.getItems().add(CheckMenuItemBuilder.create().text("Item 2").selected(true).build());
    menuBar.getMenus().add(tools);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    root.getChildren().add(menuBar);//from w w w  .  ja va  2  s .c  o m
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu tools = new Menu("Your Menu");
    CheckMenuItem item = new CheckMenuItem("Item 1");

    tools.getItems().add(item);/*w w w  .java 2s . c  om*/

    tools.getItems().add(CheckMenuItemBuilder.create().text("Item 2").selected(true).build());
    menuBar.getMenus().add(tools);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

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

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu menu = new Menu("File");
    menu.getItems().add(new MenuItem("New"));
    menu.getItems().add(new MenuItem("Save"));
    menu.getItems().add(new SeparatorMenuItem());
    menu.getItems().add(new MenuItem("Exit"));

    menuBar.getMenus().add(menu);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    root.getChildren().add(menuBar);//from ww w .  jav  a  2 s . c  o m
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu tools = new Menu("Your Menu");
    CheckMenuItem item = new CheckMenuItem();
    item.setText("Item 1");
    tools.getItems().add(item);/* w ww. jav  a2  s  .c o  m*/

    tools.getItems().add(CheckMenuItemBuilder.create().text("Item 2").selected(true).build());
    menuBar.getMenus().add(tools);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

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

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
    root.setTop(menuBar);/*from w ww  .  jav  a2 s .c o m*/

    Menu fileMenu = new Menu("File");
    MenuItem exitMenuItem = new MenuItem("Exit");
    fileMenu.getItems().add(exitMenuItem);
    exitMenuItem.setOnAction(actionEvent -> Platform.exit());

    menuBar.getMenus().addAll(fileMenu);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu menu = new Menu("File");
    MenuItem newItem = new MenuItem("New");
    menu.getItems().add(newItem);//from w w  w.ja  v a2s . c om
    menu.getItems().add(new MenuItem("Save"));
    menu.getItems().add(new SeparatorMenuItem());
    menu.getItems().add(new MenuItem("Exit"));

    newItem.setVisible(false);

    menuBar.getMenus().add(menu);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

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

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu tools = new Menu("Your Menu");

    Image image = new Image(getClass().getResourceAsStream("a.png"));

    CheckMenuItem item = new CheckMenuItem("Item 1", new ImageView(image));
    tools.getItems().add(item);//from   w ww  . j a va2s  .  co m

    tools.getItems().add(CheckMenuItemBuilder.create().text("Item 2").selected(true).build());
    menuBar.getMenus().add(tools);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

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