
import javafx.application.Application;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class SelectedText extends Application {

    @Override
    public void start(Stage primaryStage) {
        TextField textField = new TextField();

        StackPane root = new StackPane();
        root.getChildren().add(textField);

        Scene scene = new Scene(root, 100, 100);

        primaryStage.setScene(scene);
        primaryStage.show();

        textField.selectedTextProperty().addListener((final ObservableValue<? extends String> ov,
                final String oldSelection, final String newSelection) -> {
                    System.out.println ("text selected: " + newSelection); 
                });
				
				
				
        }

    public static void main(String[] args) {
        launch(args);
    }  
}
