/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ package tests; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.Group; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.TextField; public class MenuTest extends Application { int index = 1; @Override public void start(Stage stage) { stage.setTitle("Hello Menu"); stage.setWidth(500); stage.setHeight(500); Scene scene = createScene(); scene.setFill(Color.WHITE); stage.setScene(scene); stage.show(); } private Scene createScene() { final Scene scene = new Scene(new Group()); final MenuBar menuBar = new MenuBar(); final Menu fileMenu = new Menu("File"); final Menu actionsMenu = new Menu("Save"); fileMenu.getItems().setAll(actionsMenu); menuBar.getMenus().add(fileMenu); TextField textfield = new TextField("hello world"); textfield.setLayoutX(10); textfield.setLayoutY(50); textfield.setPrefWidth(100); Group root = (Group) scene.getRoot(); root.getChildren().clear(); root.getChildren().addAll(menuBar, textfield); return scene; } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(MenuTest.class, args); } }