List of usage examples for javafx.scene.control MenuBar prefWidthProperty
public final DoubleProperty prefWidthProperty()
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 www. j a va2s . c o m 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(); }
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 . java 2 s . 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(); }