package fxsqe; import com.sun.javafx.runtime.VersionInfo; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class MenuTest extends Application implements ChangeListener { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) { BorderPane root = new BorderPane(); final Menu menu1 = new Menu("top"); MenuBar menuBar = new MenuBar(); menuBar.getMenus().addAll(menu1); menu1.getItems().add(new Menu("foo")); TextField tf = new TextField("TextField"); root.setTop(menuBar); root.setCenter(new Group(tf)); stage.setTitle(VersionInfo.getRuntimeVersion()); stage.setScene(new Scene(root, 300, 250)); stage.show(); menuBar.setFocusTraversable(false); menuBar.focusedProperty().addListener(this); tf.focusedProperty().addListener(this); tf.requestFocus(); } @Override public void changed(ObservableValue ov, Object t, Object t1) { System.out.println("focus gained - " + ov.toString()); } }