List of usage examples for javafx.scene.control MenuBar getMenus
public final ObservableList<Menu> getMenus()
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 w w.ja v a2 s. c o 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(Stage primaryStage) { primaryStage.setTitle("Title"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); MenuBar menuBar = new MenuBar(); EventHandler<ActionEvent> action = changeTabPlacement(); Menu menu = new Menu("Direction"); MenuItem left = new MenuItem("Left"); left.setOnAction(action);//w ww . j a v a 2s. co m menu.getItems().add(left); MenuItem right = new MenuItem("Right"); right.setOnAction(action); menu.getItems().add(right); MenuItem top = new MenuItem("Top"); top.setOnAction(action); menu.getItems().add(top); MenuItem bottom = new MenuItem("Bottom"); bottom.setOnAction(action); menu.getItems().add(bottom); menuBar.getMenus().add(menu); BorderPane borderPane = new BorderPane(); borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); borderPane.setTop(menuBar); root.getChildren().add(borderPane); 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/* w w w . j a v a 2s.c om*/ 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//from w w w. j av a2s . 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
@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("Radio Button Menu Item"); ToggleGroup tGroup = new ToggleGroup(); RadioMenuItem soundAlarmItem = RadioMenuItemBuilder.create().toggleGroup(tGroup).text("On").build(); RadioMenuItem stopAlarmItem = RadioMenuItemBuilder.create().toggleGroup(tGroup).text("Off").selected(true) .build();/* w w w. j ava 2s.c o m*/ stopAlarmItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("radio toggled"); } }); menu.getItems().add(soundAlarmItem); menu.getItems().add(stopAlarmItem); menuBar.prefWidthProperty().bind(primaryStage.widthProperty()); 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"); ToggleGroup modalGroup = new ToggleGroup(); RadioMenuItem nonModalItem = RadioMenuItemBuilder.create().toggleGroup(modalGroup).text("On").selected(true) .build();// w ww .ja v a2s .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:io.github.moosbusch.permagon.configuration.builder.spi.AbstractPermagonBuilder.java
protected void buildMenuBar(MenuBar pane) { if (containsKey(NODE_MENUS_PROPERTY)) { Object obj = Objects.requireNonNull(get(NODE_MENUS_PROPERTY)); if (obj instanceof ObservableMap) { ObservableMap propertiesMap = (ObservableMap) obj; propertiesMap.values().stream().filter((propertyValue) -> (propertyValue instanceof ObservableList)) .forEach((propertyValue) -> { pane.getMenus().addAll((ObservableList) propertyValue); });//from www. ja v a 2 s . c o m } } }
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 ww w . j a va2 s .c om // File menu - new, save, exit Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New"); MenuItem saveMenuItem = new MenuItem("Save"); MenuItem exitMenuItem = new MenuItem("Exit"); exitMenuItem.setOnAction(actionEvent -> Platform.exit()); fileMenu.getItems().addAll(newMenuItem, saveMenuItem, new SeparatorMenuItem(), exitMenuItem); Menu webMenu = new Menu("Web"); CheckMenuItem htmlMenuItem = new CheckMenuItem("HTML"); htmlMenuItem.setSelected(true); webMenu.getItems().add(htmlMenuItem); CheckMenuItem cssMenuItem = new CheckMenuItem("CSS"); cssMenuItem.setSelected(true); webMenu.getItems().add(cssMenuItem); Menu sqlMenu = new Menu("SQL"); ToggleGroup tGroup = new ToggleGroup(); RadioMenuItem mysqlItem = new RadioMenuItem("MySQL"); mysqlItem.setToggleGroup(tGroup); RadioMenuItem oracleItem = new RadioMenuItem("Oracle"); oracleItem.setToggleGroup(tGroup); oracleItem.setSelected(true); sqlMenu.getItems().addAll(mysqlItem, oracleItem, new SeparatorMenuItem()); Menu tutorialManeu = new Menu("Tutorial"); tutorialManeu.getItems().addAll(new CheckMenuItem("Java"), new CheckMenuItem("JavaFX"), new CheckMenuItem("Swing")); sqlMenu.getItems().add(tutorialManeu); menuBar.getMenus().addAll(fileMenu, webMenu, sqlMenu); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("Menu Sample"); Scene scene = new Scene(new VBox(), 400, 350); scene.setFill(Color.OLDLACE); name.setFont(new Font("Verdana Bold", 22)); binName.setFont(new Font("Arial Italic", 10)); pic.setFitHeight(150);/* ww w.jav a 2s.co m*/ pic.setPreserveRatio(true); description.setWrapText(true); description.setTextAlignment(TextAlignment.JUSTIFY); shuffle(); MenuBar menuBar = new MenuBar(); // --- Graphical elements final VBox vbox = new VBox(); vbox.setAlignment(Pos.CENTER); vbox.setSpacing(10); vbox.setPadding(new Insets(0, 10, 0, 10)); vbox.getChildren().addAll(name, binName, pic, description); // --- Menu File Menu menuFile = new Menu("File"); MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png"))); add.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { shuffle(); vbox.setVisible(true); } }); MenuItem clear = new MenuItem("Clear"); clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X")); clear.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { vbox.setVisible(false); } }); MenuItem exit = new MenuItem("Exit"); exit.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.exit(0); } }); menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit); // --- Menu Edit Menu menuEdit = new Menu("Edit"); Menu menuEffect = new Menu("Picture Effect"); final ToggleGroup groupEffect = new ToggleGroup(); for (Entry effect : effects) { RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey()); itemEffect.setUserData(effect.getValue()); itemEffect.setToggleGroup(groupEffect); menuEffect.getItems().add(itemEffect); } final MenuItem noEffects = new MenuItem("No Effects"); noEffects.setDisable(true); noEffects.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { pic.setEffect(null); groupEffect.getSelectedToggle().setSelected(false); noEffects.setDisable(true); } }); groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) { if (groupEffect.getSelectedToggle() != null) { Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData(); pic.setEffect(effect); noEffects.setDisable(false); } else { noEffects.setDisable(true); } } }); menuEdit.getItems().addAll(menuEffect, noEffects); // --- Menu View Menu menuView = new Menu("View"); CheckMenuItem titleView = createMenuItem("Title", name); CheckMenuItem binNameView = createMenuItem("Binomial name", binName); CheckMenuItem picView = createMenuItem("Picture", pic); CheckMenuItem descriptionView = createMenuItem("Decsription", description); menuView.getItems().addAll(titleView, binNameView, picView, descriptionView); menuBar.getMenus().addAll(menuFile, menuEdit, menuView); // --- Context Menu final ContextMenu cm = new ContextMenu(); MenuItem cmItem1 = new MenuItem("Copy Image"); cmItem1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putImage(pic.getImage()); clipboard.setContent(content); } }); cm.getItems().add(cmItem1); pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) cm.show(pic, e.getScreenX(), e.getScreenY()); } }); ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox); stage.setScene(scene); stage.show(); }
From source file:be.makercafe.apps.makerbench.Main.java
/** * Creates the menubar/*from ww w .ja v a2 s.co m*/ * * @return */ private MenuBar createMenuBar() { MenuBar bar = new MenuBar(); Menu projectMenu = new Menu("Project"); MenuItem openProject = new MenuItem("Open..."); openProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { directoryChooser.setTitle("Please choose a project folder"); File file = directoryChooser.showDialog(stage); viewer.setRoot(setRootFolder(file)); } }); Menu newProject = new Menu("New"); MenuItem newFolder = new MenuItem("Folder..."); newFolder.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TextInputDialog dialog = new TextInputDialog("my_project_folder"); dialog.setTitle("New folder"); dialog.setHeaderText("Create a new folder"); dialog.setContentText("Folder name:"); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { String homeDir = System.getProperty("user.home"); System.out.println("Folder name: " + result.get()); System.out.println("User home: " + homeDir); } } }); newProject.getItems().add(newFolder); MenuItem importProject = new MenuItem("Import"); importProject.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.CONTROL_DOWN)); importProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Import"); } }); MenuItem deleteProject = new MenuItem("Delete"); deleteProject.setAccelerator(new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN)); deleteProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Delete"); } }); projectMenu.getItems().addAll(openProject, newProject, importProject, deleteProject); Menu helpMenu = new Menu("Help"); MenuItem aboutItem = new MenuItem("About"); aboutItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Information Dialog"); alert.setHeaderText("About makerbench"); alert.setContentText( "Makerbench is an open source IDE for designing and manufacturing objects and code.\nWritten by Luc De pauw\n\nUses opensource libraries from the next projects:\n-RichtextFX by Tomas Mikula\n-JCSG by Michael Hoffer\n-ControlsFX by FXexperience.com"); alert.showAndWait(); } }); helpMenu.getItems().add(aboutItem); bar.getMenus().addAll(projectMenu, helpMenu); return bar; }