List of usage examples for javafx.scene.control MenuItem MenuItem
public MenuItem(String text, Node graphic)
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.setOnShowing(new EventHandler<Event>() { @Override/*from ww w . ja v a2s .c om*/ public void handle(Event arg0) { } }); System.out.println(menu.getOnShowing()); MenuItem newItem = new MenuItem("New", null); 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 . ja v a 2 s .co 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/* www. ja v a2 s . c om*/ 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 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);/*from w w w .j a v a 2 s.c o 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:org.sleuthkit.autopsy.imageanalyzer.gui.GroupPane.java
private MenuItem createGrpCatMenuItem(final Category cat) { final MenuItem menuItem = new MenuItem(cat.getDisplayName(), new ImageView(DrawableAttribute.CATEGORY.getIcon())); menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override//w w w .j ava 2s.c om public void handle(ActionEvent t) { selectAllFiles(); new CategorizeAction().addTag(cat.getTagName(), ""); grpCatSplitMenu.setText(cat.getDisplayName()); grpCatSplitMenu.setOnAction(this); } }); return menuItem; }
From source file:org.sleuthkit.autopsy.imagegallery.gui.GroupPane.java
private MenuItem createGrpCatMenuItem(final Category cat) { final MenuItem menuItem = new MenuItem(cat.getDisplayName(), new ImageView(DrawableAttribute.CATEGORY.getIcon())); menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override/*from w w w.j a v a2 s. c o m*/ public void handle(ActionEvent t) { Set<Long> fileIdSet = new HashSet<>(getGrouping().fileIds()); new CategorizeAction().addTagsToFiles(cat.getTagName(), "", fileIdSet); grpCatSplitMenu.setText(cat.getDisplayName()); grpCatSplitMenu.setOnAction(this); } }); return menuItem; }
From source file:org.sleuthkit.autopsy.imageanalyzer.gui.GroupPane.java
private MenuItem createGrpTagMenuItem(final TagName tn) { final MenuItem menuItem = new MenuItem(tn.getDisplayName(), new ImageView(DrawableAttribute.TAGS.getIcon())); menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override//from w w w. ja va 2 s. c o m public void handle(ActionEvent t) { selectAllFiles(); AddDrawableTagAction.getInstance().addTag(tn, ""); grpTagSplitMenu.setText(tn.getDisplayName()); grpTagSplitMenu.setOnAction(this); } }); return menuItem; }
From source file:org.sleuthkit.autopsy.imagegallery.gui.GroupPane.java
private MenuItem createGrpTagMenuItem(final TagName tn) { final MenuItem menuItem = new MenuItem(tn.getDisplayName(), new ImageView(DrawableAttribute.TAGS.getIcon())); menuItem.setOnAction(new EventHandler<ActionEvent>() { @Override/*from w w w. j a va2 s. c o m*/ public void handle(ActionEvent t) { Set<Long> fileIdSet = new HashSet<>(getGrouping().fileIds()); AddDrawableTagAction.getInstance().addTagsToFiles(tn, "", fileIdSet); grpTagSplitMenu.setText(tn.getDisplayName()); grpTagSplitMenu.setOnAction(this); } }); return menuItem; }