How to change text position in window in javaFX
<p>In my program a text field takes value from the user and shows the value in the window. But i want show the texts in the right of the window.</p>

<p>I used <strong>setTextAlignment(TextAlignment.RIGHT)</strong> but it still shows texts in the left(I'm not sure whether it is the right method to call).</p>

<p>How can i solve it?</p>

<pre><code>public class ChatBox extends Application{

    final ScrollPane sp = new ScrollPane();
    public void start(Stage stage){
    TextFlow textFlow = new TextFlow();
    textFlow.setPadding(new Insets(10));
    textFlow.setLineSpacing(10);
    TextField textField = new TextField();
    textField.setPrefSize(50,30);
    Button button = new Button("Send");
    button.setPrefSize(80,30);
    VBox container = new VBox();
    VBox box = new VBox();
    box.getChildren().addAll(sp,textFlow);
    container.setPadding(new Insets(10));
    container.getChildren().addAll(box, new HBox(textField, button));
    VBox.setVgrow(sp, Priority.ALWAYS);
    VBox.setVgrow(textFlow, Priority.ALWAYS);

textField.prefWidthProperty().bind(container.widthProperty().subtract(button.prefWidthProperty()));

textField.setOnKeyPressed(e -&gt; {
    if(e.getCode() == KeyCode.ENTER) {
        playSound();
        button.fire();
    }
});
button.setOnAction(e -&gt; {
    Text text;
    if(textFlow.getChildren().size()==0){
        text = new Text(textField.getText());
        text.setTextAlignment(TextAlignment.RIGHT);
        String str = textField.getText();
        System.out.println(str);
    } else {
        text = new Text("\n" + textField.getText());
        text.setTextAlignment(TextAlignment.RIGHT);
    }
    textFlow.getChildren().add(text);
    textField.clear();
    textField.requestFocus();
});
VBox vb = new VBox();
vb.getChildren().addAll(textFlow);
sp.setVmax(440);
sp.setPrefSize(400, 300);
sp.setContent(vb);
sp.vvalueProperty().bind((ObservableValue&lt;? extends Number&gt;) vb.heightProperty());
Scene scene = new Scene(container, 400, 300);
stage.setScene(scene);
stage.setTitle("jui");
stage.show();
}
}
</code></pre>