Java FX TextArea Alignment

Viewed 15004

I want to display a text inside a Java FX Text area.

My code is:

TextArea txt = new TextArea();
txt.setEditable(false);
txt.setStyle("-fx-font-alignment: center");
txt.setText(text);

But I'm not able to set a text alignment (inside the TextArea)

I tried this:

txt.setStyle("-fx-font-alignment: center");

But it didn't work

5 Answers

I found a solution for centering horizontally the content of textarea only using CSS.

i have used a class in css:

.centeredTextArea .scroll-pane .content .text {
    -fx-text-alignment: center;
}

and after i have added

styleClass="centeredTextArea"

to my textArea control.

I don't know why you want to use a textArea, but if you just want to display some text you should use a TextField.

Or else to display text use:

Text text = new Text("text");

But i don't know what exactly it is that you want to do.

Related