/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javafxapplication13; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextBox; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.application.Platform; import javafx.scene.layout.VBox; /** * * @author Jean */ public class JavaFXApplication13 extends Application { /** * @param args the command line arguments */ private TextBox ed1 = new TextBox(); private TextBox ed2 = new TextBox(); private TextBox ed3 = new TextBox(); private TextBox ed4 = new TextBox(); public static void main(String[] args) { Application.launch(JavaFXApplication13.class, args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello World"); Group root = new Group(); VBox vb = new VBox(); System.out.println(vb.getHeight()); Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN); Button btn = new Button(); btn.setText("Hello World"); root.getChildren().add(vb); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); vb.getChildren().add(btn); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); vb.getChildren().add(ed1); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); vb.getChildren().add(ed2); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); vb.getChildren().add(ed3); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); vb.getChildren().add(ed4); System.out.println(vb.getHeight()); System.out.println(vb.getLayoutBounds()); System.out.println(vb.getBoundsInLocal()); System.out.println(vb.getBoundsInParent()); ed2.focusedProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { if (oldValue != newValue) { if (ed2.getRawText().length()<5) { Platform.runLater(new Runnable() { public void run() { ed2.requestFocus(); } }); System.out.println("ops"); } } } }); primaryStage.setScene(scene); primaryStage.setVisible(true); } }