import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.stage.Stage; import javafx.scene.text.Text; import javafx.scene.control.TextField; public class TextWrappingTest extends Application { static final String complextext = "The quick brown fox jumps over the lazy dog.\nWoven silk pyjamas exchanged for blue quartz?\nHave a pick: twenty six letters - no forcing a jumbled quiz!\n"; int wrappingwidth = 0; Text text; TextField tf; public static void main(String[] args) { Application.launch(TextWrappingTest.class, args); } public void start(Stage stage) { VBox pane = new VBox(); Scene scene = new Scene(pane, 500, 200); stage.setScene(scene); tf = new TextField("wrapping width"); tf.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent e) { if (e.getCode().equals(KeyCode.ENTER)) { wrappingwidth = Integer.parseInt(tf.getText()); System.out.println(wrappingwidth); tf.setText(""); text.setWrappingWidth(wrappingwidth); } } }); tf.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent e) { tf.setText(""); } }); text = new Text(20, 30, complextext); text.setWrappingWidth(wrappingwidth); pane.getChildren().addAll(tf, text); stage.show(); } }