List of usage examples for javafx.scene.control MenuBar MenuBar
public MenuBar()
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 w ww.j a va 2 s. c o m 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.setOnHiding(new EventHandler<Event>() { @Override//from w w w . j a v a 2 s . c om 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(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// ww w.ja va 2 s .co m public void handle(Event arg0) { } }); MenuItem newItem = new MenuItem("New", null); newItem.setOnMenuValidation(new EventHandler<Event>() { @Override public void handle(Event arg0) { } }); 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 w w. ja v a 2 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) { 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 w w . j a v a2 s .co 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: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);//from w ww . ja v a 2 s . c o 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/*ww w .j a va2s . c o 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/* w w w . j av 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 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();//www . ja v a2s . c om 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(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 ww w. java2 s .c om*/ item.selectedProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue arg0, Object arg1, Object arg2) { } }); 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(); }