import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.MenuButton; import javafx.scene.control.MenuItem; import javafx.scene.layout.VBox; import javafx.stage.Stage; public final class MenuButtonTest extends Application { public static void main(final String[] args) { launch(args); } @Override public void start(final Stage stage) throws Exception { final Group rootGroup = new Group(); final MenuItem[] menuItems = new MenuItem[5]; for (int i = 0; i < menuItems.length; ++i) { menuItems[i] = new MenuItem("Test Menu Item-" + i); } final MenuButton mb = new MenuButton(); mb.setTranslateX(90); mb.setTranslateY(70); mb.setText("TestMenu"); mb.getItems().addAll(menuItems); final Button btn = new Button("Button"); btn.setTranslateY(160); final Label stageXLabel = new Label(); stageXLabel.textProperty().bind( stage.xProperty().asString("stage.x: %.0f")); final Label stageYLabel = new Label(); stageYLabel.textProperty().bind( stage.yProperty().asString("stage.y: %.0f")); final VBox infoGroup = new VBox(); infoGroup.getChildren().addAll(stageXLabel, stageYLabel); infoGroup.setTranslateX(90); infoGroup.setTranslateY(10); rootGroup.getChildren().addAll(mb, btn, infoGroup); final Scene scene = new Scene(rootGroup, 320, 240); stage.setTitle("Test"); stage.setScene(scene); stage.setVisible(true); } }