List of usage examples for javafx.scene Scene focusOwnerProperty
public final ReadOnlyObjectProperty<Node> focusOwnerProperty()
From source file:Main.java
@Override public void start(Stage stage) { TextField fName = new TextField(); TextField lName = new TextField(); TextField salary = new TextField(); marker = new Circle(5); marker.setManaged(false);/*from w w w.ja v a2 s.c om*/ marker.setFill(Color.RED); marker.setMouseTransparent(true); HBox hb1 = new HBox(); HBox hb2 = new HBox(); HBox hb3 = new HBox(); hb1.getChildren().addAll(new Label("First Name:"), fName); hb2.getChildren().addAll(new Label("Last Name:"), lName); hb3.getChildren().addAll(new Label("Salary:"), salary); VBox root = new VBox(); root.getChildren().addAll(hb1, hb2, hb3, marker); Scene scene = new Scene(root); scene.focusOwnerProperty().addListener((prop, oldNode, newNode) -> placeMarker(newNode)); stage.setScene(scene); stage.setTitle(""); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { TextField fName = new TextField(); TextField lName = new TextField(); TextField salary = new TextField(); Button closeBtn = new Button("Close"); closeBtn.setOnAction(e -> Platform.exit()); fName.getProperties().put("microHelpText", "Enter the first name"); lName.getProperties().put("microHelpText", "Enter the last name"); salary.getProperties().put("microHelpText", "Enter a salary greater than $2000.00."); // The help text node is unmanaged helpText.setManaged(false);//from w ww . j a v a2s.com helpText.setTextOrigin(VPos.TOP); helpText.setFill(Color.RED); helpText.setFont(Font.font(null, 9)); helpText.setMouseTransparent(true); // Add all nodes to a GridPane GridPane root = new GridPane(); root.add(new Label("First Name:"), 1, 1); root.add(fName, 2, 1); root.add(new Label("Last Name:"), 1, 2); root.add(lName, 2, 2); root.add(new Label("Salary:"), 1, 3); root.add(salary, 2, 3); root.add(closeBtn, 3, 3); root.add(helpText, 4, 3); Scene scene = new Scene(root, 300, 100); // Add a change listener to the scene, so we know when // the focus owner changes and display the micro help scene.focusOwnerProperty().addListener((ObservableValue<? extends Node> value, Node oldNode, Node newNode) -> focusChanged(value, oldNode, newNode)); stage.setScene(scene); stage.setTitle("Showing Micro Help"); stage.show(); }