package threadsissue; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextArea; import javafx.scene.layout.Pane; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { launch(args); } String text = "one two three four five"; @Override public void start(Stage stage) throws Exception { final TextArea tf = new TextArea(text); tf.setPrefSize(50, 50); new Thread(new Runnable() { public void run() { try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } for (int i = 1; i < 10; i++) { for (int j = 0; j < text.length() + 1; j++) { final int parameter = j; com.sun.javafx.application.PlatformImpl.runAndWait(new Runnable() { public void run() { tf.positionCaret(parameter); tf.selectPreviousWord(); } }); try { Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Selection : " + tf.getSelectedText()); } } } }).start(); Pane vb = new Pane(); vb.getChildren().addAll(tf); Scene scene = new Scene(vb, 300, 300); stage.setScene(scene); stage.show(); } }