Example usage for javafx.scene.control MenuBar MenuBar

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

Introduction

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

Prototype

public MenuBar() 

Source Link

Document

Creates a new empty MenuBar.

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 exitItem = new MenuItem("Exit", null);
    exitItem.setMnemonicParsing(true);/*from w w w. j  a v  a2  s.c  om*/
    exitItem.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN));
    exitItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            Platform.exit();
        }
    });
    menu.getItems().add(exitItem);

    menuBar.getMenus().add(menu);
    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");
    final MenuItem aboutMenuItem = MenuItemBuilder.create().text("About")
            .onAction(new EventHandler<ActionEvent>() {
                @Override// ww  w  .ja va  2  s . com
                public void handle(ActionEvent e) {
                    System.out.println("You clicked on About!");
                }
            }).accelerator(new KeyCodeCombination(KeyCode.A, KeyCombination.CONTROL_DOWN)).build();
    menu.getItems().add(aboutMenuItem);

    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(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");

    ToggleGroup modalGroup = new ToggleGroup();
    RadioMenuItem nonModalItem = RadioMenuItemBuilder.create().toggleGroup(modalGroup).text("On").selected(true)
            .build();//from  w w w  . j a  va  2 s . c  o m
    nonModalItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });

    menu.getItems().add(nonModalItem);
    RadioMenuItem modalItem = RadioMenuItemBuilder.create().toggleGroup(modalGroup).text("Off").selected(true)
            .build();
    modalItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }
    });
    menu.getItems().add(modalItem);
    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(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);/*w  w w.j a va  2  s . c  om*/

    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) {
    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);/* w ww  .  j  a v  a 2  s  . c  om*/
    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:jviewmda.JViewMda.java

@Override
public void start(Stage primaryStage) {
    m_stage = primaryStage;//from   w w  w.j  av a 2s .com

    String array_path = "";
    Parameters params = getParameters();
    List<String> unnamed_params = params.getUnnamed();
    if (unnamed_params.size() > 0) {
        array_path = unnamed_params.get(0);
    }
    // FOR DEBUGING PURPOSES
    if (array_path.length() == 0) {
        //String debug_path = "/home/magland/wisdm/www/wisdmfileserver/files/fetalmri/sessions/SESSION1/crops/FNP001A-coronal.crop.mda";
        String debug_path = "/home/magland/data/LesionProbe/Images/ID001_FLAIR.nii";
        if ((new File(debug_path)).exists()) {
            array_path = debug_path;
        }
    }

    Menu menu;
    MenuItem item;

    MenuBar menubar = new MenuBar();

    //file menu
    menu = new Menu("File");
    menubar.getMenus().add(menu);
    item = new MenuItem("Open...");
    item.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_open());
    menu.getItems().add(item);
    item = new MenuItem("Save As...");
    item.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_saveas());
    menu.getItems().add(item);
    menu.getItems().add(new SeparatorMenuItem()); /////////////////////////////////////////////
    item = new MenuItem("Exit");
    item.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_file_exit());
    menu.getItems().add(item);

    //view menu
    menu = new Menu("View");
    menubar.getMenus().add(menu);
    item = new MenuItem("Zoom In");
    item.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN));
    item.setOnAction(e -> on_zoom_in());
    menu.getItems().add(item);
    item = new MenuItem("Zoom Out");
    item.setAccelerator(
            new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
    item.setOnAction(e -> on_zoom_out());
    menu.getItems().add(item);
    menu.getItems().add(new SeparatorMenuItem()); /////////////////////////////////////////////
    {
        CheckMenuItem item0 = new CheckMenuItem("Top Controls");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setTopControlsVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Bottom Controls");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setBottomControlsVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Brightness/Contrast");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setBrightnessContrastVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }
    {
        CheckMenuItem item0 = new CheckMenuItem("Slice Slider");
        item0.setSelected(true);
        item0.setOnAction(e -> {
            m_widget.setSliceSliderVisible(item0.isSelected());
        });
        menu.getItems().add(item0);
    }

    //selection menu
    menu = new Menu("Selection");
    menubar.getMenus().add(menu);
    Map<String, CheckMenuItem> mode_items = new HashMap<>();
    m_selection_mode_items = mode_items;
    mode_items.put("rectangle", new CheckMenuItem("Rectangle"));
    mode_items.put("ellipse", new CheckMenuItem("Ellipse"));
    Set<String> keys = mode_items.keySet();
    for (String key : keys) {
        CheckMenuItem item0 = mode_items.get(key);
        menu.getItems().add(item0);
        item0.setOnAction(evt -> {
            on_selection_mode_changed(key);
        });

    }
    mode_items.get("rectangle").setSelected(true);

    VBox root = new VBox();
    root.getChildren().addAll(menubar, m_widget);

    Scene scene = new Scene(root, 500, 450);

    primaryStage.setTitle("JViewMda");
    primaryStage.setScene(scene);
    primaryStage.show();

    if (array_path.length() > 0) {
        open_file(array_path);
    }

    m_prefs = Preferences.userNodeForPackage(this.getClass());

}

From source file:ijfx.ui.canvas.FxCanvasTester.java

@Override
public void start(Stage primaryStage) {

    final SCIFIO scifio = new SCIFIO();
    MenuBar menuBar = new MenuBar();
    InputControl parameterInput = null;//from   w w  w .  j a  v  a  2  s.  c  o m
    try {
        System.setProperty("imagej.legacy.sync", "true");
        //reader.getContext().inject(this);
        ImageJ imagej = new ImageJ();
        context = imagej.getContext();
        CommandInfo command = imagej.command().getCommand(GaussianBlur.class);

        CommandModuleItem input = command.getInput("sigma");
        Class<?> type = input.getType();
        if (type == double.class) {
            type = Double.class;
        }

        context.inject(this);

        GaussianBlur module = new GaussianBlur();

        imagej.ui().showUI();

        //reader = scifio.initializer().initializeReader("./stack.tif");
        commandService.run(OpenFile.class, true, new HashMap<String, Object>());

        menuBar = new MenuBar();
        menuService.createMenus(new FxMenuCreator(), menuBar);
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule simpleModule = new SimpleModule("ModuleSerializer");
        // simpleModule.addSerializer(ModuleItem<?>.class,new ModuleItemSerializer());
        simpleModule.addSerializer(ModuleInfo.class, new ModuleSerializer());
        simpleModule.addSerializer(ModuleItem.class, new ModuleItemSerializer());
        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        mapper.registerModule(simpleModule);

        mapper.writeValue(new File("modules.json"), moduleService.getModules());

    } catch (Exception ex) {
        ImageJFX.getLogger();
    }

    //imageView.fitImageToScreen();
    Button reset = new Button("Reset");

    reset.setOnAction(event -> update());

    BorderPane pane = new BorderPane();

    Button test = new Button("Test");

    AnchorPane root = new AnchorPane();
    root.getChildren().add(pane);
    root.getStylesheets().add(ArcMenu.class.getResource("arc-default.css").toExternalForm());
    root.getStylesheets().add(ImageJFX.class.getResource(("flatterfx.css")).toExternalForm());
    AnchorPane.setTopAnchor(pane, 0.0);
    AnchorPane.setBottomAnchor(pane, 0.0);
    AnchorPane.setLeftAnchor(pane, 0.0);
    AnchorPane.setRightAnchor(pane, 0.0);
    pane.setTop(menuBar);

    HBox vbox = new HBox();
    vbox.getChildren().addAll(reset, test, parameterInput);
    vbox.setSpacing(10);
    vbox.setPadding(new Insets(10, 10, 10, 10));
    // update();
    pane.setCenter(ImageWindowContainer.getInstance());
    // pane.setPrefSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    pane.setBottom(vbox);

    Scene scene = new Scene(root, 600, 600);

    test.setOnAction(event -> {

        test();
    });

    primaryStage.setTitle("ImageCanvasTest");
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.cdd.bao.editor.EditSchema.java

public EditSchema(Stage stage) {
    this.stage = stage;

    if (MainApplication.icon != null)
        stage.getIcons().add(MainApplication.icon);

    menuBar = new MenuBar();
    menuBar.setUseSystemMenuBar(true);// ww w .  jav  a 2 s  . c o  m
    menuBar.getMenus().add(menuFile = new Menu("_File"));
    menuBar.getMenus().add(menuEdit = new Menu("_Edit"));
    menuBar.getMenus().add(menuValue = new Menu("_Value"));
    menuBar.getMenus().add(menuView = new Menu("Vie_w"));
    createMenuItems();

    treeRoot = new TreeItem<>(new Branch(this));
    treeView = new TreeView<>(treeRoot);
    treeView.setEditable(true);
    treeView.setCellFactory(p -> new HierarchyTreeCell());
    treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldVal, newVal) -> {
        if (oldVal != null)
            pullDetail(oldVal);
        if (newVal != null)
            pushDetail(newVal);
    });
    treeView.focusedProperty()
            .addListener((val, oldValue, newValue) -> Platform.runLater(() -> maybeUpdateTree()));

    detail = new DetailPane(this);

    StackPane sp1 = new StackPane(), sp2 = new StackPane();
    sp1.getChildren().add(treeView);
    sp2.getChildren().add(detail);

    splitter = new SplitPane();
    splitter.setOrientation(Orientation.HORIZONTAL);
    splitter.getItems().addAll(sp1, sp2);
    splitter.setDividerPositions(0.4, 1.0);

    progBar = new ProgressBar();
    progBar.setMaxWidth(Double.MAX_VALUE);

    root = new BorderPane();
    root.setTop(menuBar);
    root.setCenter(splitter);
    root.setBottom(progBar);

    BorderPane.setMargin(progBar, new Insets(2, 2, 2, 2));

    Scene scene = new Scene(root, 1000, 800, Color.WHITE);

    stage.setScene(scene);

    treeView.setShowRoot(false);
    treeRoot.getChildren().add(treeTemplate = new TreeItem<>(new Branch(this, "Template")));
    treeRoot.getChildren().add(treeAssays = new TreeItem<>(new Branch(this, "Assays")));
    treeTemplate.setExpanded(true);
    treeAssays.setExpanded(true);

    rebuildTree();

    Platform.runLater(() -> treeView.getFocusModel().focus(treeView.getSelectionModel().getSelectedIndex())); // for some reason it defaults to not the first item

    stage.setOnCloseRequest(event -> {
        if (!confirmClose())
            event.consume();
    });

    updateTitle();

    // loading begins in a background thread, and is updated with a status bar
    Vocabulary.Listener listener = new Vocabulary.Listener() {
        public void vocabLoadingProgress(Vocabulary vocab, float progress) {
            Platform.runLater(() -> {
                progBar.setProgress(progress);
                if (vocab.isLoaded())
                    root.getChildren().remove(progBar);
            });
        }

        public void vocabLoadingException(Exception ex) {
            ex.printStackTrace();
        }
    };
    Vocabulary.globalInstance(listener);
}

From source file:de.pixida.logtest.designer.MainWindow.java

private Node createMenuBar() {
    final MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(this.createMenus());
    return menuBar;
}

From source file:org.samcrow.frameviewer.App.java

private MenuBar createMenuBar() {
    MenuBar bar = new MenuBar();

    return bar;
}