List of usage examples for javafx.scene.control MenuItem setOnAction
public final void setOnAction(EventHandler<ActionEvent> value)
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); menu.getItems().add(left);/*from w w w . j a va 2 s . c o m*/ 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(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); }/*from w ww . j a v a 2s . com*/ }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); final ContextMenu contextMenu = new ContextMenu(item1, item2); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); } }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); System.out.println(contextMenu.onActionProperty()); contextMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("on"); } }); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); }//from w ww. ja v a2 s .c o m }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); final ContextMenu contextMenu = new ContextMenu(item1, item2); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); } }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); System.out.println(contextMenu.onActionProperty()); contextMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("on"); } }); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); contextMenu.show(grid, 20, 20); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); TextField notification = new TextField(); MenuItem item1 = new MenuItem("About"); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("About"); }/*from w w w .j av a 2s .co m*/ }); MenuItem item2 = new MenuItem("Preferences"); item2.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("Preferences"); } }); final ContextMenu contextMenu = new ContextMenu(item1, item2); contextMenu.setOnShowing(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("showing"); } }); contextMenu.setOnShown(new EventHandler<WindowEvent>() { public void handle(WindowEvent e) { System.out.println("shown"); } }); System.out.println(contextMenu.onActionProperty()); contextMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("on"); } }); notification.setContextMenu(contextMenu); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(notification, 1, 0); contextMenu.show(grid, Side.BOTTOM, 20, 20); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.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);// w ww . j a va 2 s . c o m // 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:ubicrypt.ui.tree.FolderItem.java
public FolderItem(final Path path, final EventHandler<ActionEvent> onAddHandler) { checkArgument(path != null, "path must not be null"); this.path = path; label = null;/*from w w w . j a va 2 s. c om*/ final MenuItem add = new MenuItem("Add File"); add.setOnAction(onAddHandler); menu.getItems().add(add); }
From source file:ubicrypt.ui.files.FolderItem.java
public FolderItem(final Path path, final EventHandler<ActionEvent> onAddHandler, final EventHandler<ActionEvent> onAddFolder) { checkArgument(path != null, "path must not be null"); this.path = path; label = null;/*from w ww. j a v a2 s . c om*/ final MenuItem add = new MenuItem("Add Files"); add.setOnAction(onAddHandler); final MenuItem addFolder = new MenuItem("Add Folder"); addFolder.setOnAction(onAddFolder); menu.getItems().addAll(add, addFolder); }
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 ava2 s .c o m*/ 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:account.management.controller.ViewSalaryVoucherController.java
/** * Initializes the controller class.//www . j a v a 2 s. c om */ @Override public void initialize(URL url, ResourceBundle rb) { this.voucher_no.setCellValueFactory(new PropertyValueFactory("id")); this.date.setCellValueFactory(new PropertyValueFactory("date")); this.section.setCellValueFactory(new PropertyValueFactory("section")); this.name.setCellValueFactory(new PropertyValueFactory("name")); this.basis.setCellValueFactory(new PropertyValueFactory("basis")); this.amount.setCellValueFactory(new PropertyValueFactory("total")); final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem(" View "); item1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Data.salaryVoucher = table.getSelectionModel().getSelectedItem(); try { Parent root = FXMLLoader .load(getClass().getResource(MetaData.viewPath + "EditSalaryVoucher.fxml")); Scene scene = new Scene(root); Stage stage = new Stage(); scene.setRoot(root); stage.setResizable(false); stage.setTitle("Salary Voucher"); stage.setScene(scene); stage.showAndWait(); int index = table.getSelectionModel().getSelectedIndex(); getData(); } catch (IOException ex) { Logger.getLogger(ViewSalaryVoucherController.class.getName()).log(Level.SEVERE, null, ex); } } }); contextMenu.getItems().addAll(item1); this.table.setContextMenu(contextMenu); }
From source file:com.properned.application.LocaleListCell.java
private MenuItem getDeleteMenu(Locale locale) { MenuItem deleteMenu = new MenuItem(MessageReader.getInstance().getMessage("action.deleteMessageKey")); deleteMenu.setOnAction(new EventHandler<ActionEvent>() { @Override// w ww .ja v a 2 s .c om public void handle(ActionEvent event) { logger.info("Clic on delete button for locale '" + locale.toString() + "'"); String fileName = properties.getMapPropertiesFileByLocale().get(locale).getAbsolutePath(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.title")); alert.setHeaderText(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.header")); alert.setContentText( MessageReader.getInstance().getMessage("manageLocale.confirmDelete.content", fileName)); Optional<ButtonType> result = alert.showAndWait(); if (result.isPresent() && result.get() == ButtonType.OK) { logger.info("User say OK to the confirm"); properties.deleteLocale(locale); // Reload list controller.initializeList(); } } }); if (properties.getMapPropertiesByLocale().keySet().size() <= 1) { // We can delete only if there is more than the current locale deleteMenu.setDisable(true); } return deleteMenu; }