package textfieldsizetest; import com.sun.javafx.runtime.VersionInfo; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.text.Font; import javafx.stage.Stage; public class TextFieldSizeTest extends Application { TextField textField; Button btnInc; Button btnDec; @Override public void start(Stage primaryStage) { primaryStage.setTitle(VersionInfo.getRuntimeVersion()); primaryStage.setScene(getScene()); primaryStage.show(); } public static void main(String[] args) { launch(args); } private Scene getScene() { textField = new TextField("sample text"); btnInc = new Button("Font 20"); btnInc.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { textField.setFont(new Font(20)); System.out.println("font = 20; height = " + textField.getHeight() + "; width = " + textField.getWidth()); } }); btnDec = new Button("Font 10"); btnDec.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { textField.setFont(new Font(10)); System.out.println("font = 10; height = " + textField.getHeight() + "; width = " + textField.getWidth()); } }); HBox root = new HBox(10.0); root.getChildren().addAll(textField, btnInc, btnDec); return new Scene(root, 300, 250); } }