import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.beans.property.SimpleDoubleProperty; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Duration; public class TestShrink extends Application { private class ShrinkableTextArea extends TextArea { final SimpleDoubleProperty scale = new SimpleDoubleProperty(1.0); public ShrinkableTextArea(String content) { super(content); setMinHeight(0.0); scale.addListener((observable, oldVal, newVal) -> setPrefHeight(newVal.doubleValue() * computePrefHeight(9999))); } } @Override public void start(Stage primaryStage) throws Exception { ShrinkableTextArea area = new ShrinkableTextArea("Some amount\nof text\nin this box\netc"); area.setMaxWidth(300.0); // Wrap text makes no difference here: //area.setWrapText(true); Button shrink = new Button("Shrink"); // Scales text area to nothing shrink.setOnAction(e -> { new Timeline(new KeyFrame(Duration.millis(2000), new KeyValue(area.scale, 0.0))).play(); }); shrink.setLayoutX(300); shrink.setLayoutY(50); VBox outer = new VBox(); outer.getChildren().addAll(new Label("Start"), area, new Label("End")); Pane p = new Pane(outer, shrink); p.setMinWidth(400); p.setMinHeight(600); primaryStage.setScene(new Scene(p)); primaryStage.show(); } }