/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. */ package tests; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyCombination; import javafx.stage.Stage; /** * * @author slions */ public class TestMenus extends Application { public void start(Stage stage) { stage.setTitle("Sample"); final Scene scene = new Scene(new Group(), 500, 500); /////////////////////////////////////// final TextField tf = new TextField("TextField"); tf.setLayoutX(100); tf.setLayoutY(100); final ObservableList list = FXCollections.observableArrayList(); list.addAll("toto", "titi", "tutu"); final ComboBox cb = new ComboBox(list); cb.setEditable(true); cb.setPrefWidth(100); cb.setPromptText("empty"); cb.setLayoutX(100); cb.setLayoutY(200); /////////////////////////////////////// final MenuItem undoMenuItem = new MenuItem("Undo"); undoMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCombination.META_DOWN)); undoMenuItem.setOnAction(new EventHandler() { public void handle(ActionEvent event) { System.out.println("==>> UNDO Menu onAction called = " + scene.getFocusOwner()); } }); final Menu mainMenu = new Menu("Main"); mainMenu.getItems().addAll(undoMenuItem); final MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(mainMenu); // menuBar.setUseSystemMenuBar(true); final Group root = (Group) scene.getRoot(); root.getChildren().clear(); root.getChildren().addAll(menuBar, tf, cb); stage.setScene(scene); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }