0

I know I am supposed to set -fx-text-alignment: center; in order to achieve a center-aligned textarea.

#txtFaContent
{
    -fx-text-alignment: center;
}

with txtFaContent being the ID of my textarea (as well as its variable name inside the controller). But it doesn't have any effect on the text alignment of my textarea (I played with right/left/center; but no success).

Have I missed anything?

Joseph_Marzbani
  • 1,796
  • 4
  • 22
  • 36

1 Answers1

0

Add style class in your TextArea.text:

TextArea textArea = new TextArea();
textArea.getStyleClass().add("centered-text-area");

Add .text in your CSS:

.centered-text-area .text {
  -fx-text-alignment: center;
}
Cem Ikta
  • 1,330
  • 12
  • 12
  • is "text" a substructure of textarea? I couldn't find it in the Oracle's CSS reference guide. – Joseph_Marzbani Jun 19 '20 at 15:21
  • TextArea has all properties of TextInputControl and lot of inherited properties of other controls. Please see CSS Reference > Inheritance: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#text-area – Cem Ikta Jun 19 '20 at 15:35
  • I've been reading that reference all the day. But sorry, I can't still understand how that ".text" is related to text-area. I know a TextArea inherits from other Classes (TextInputControl, ScrolPane, Region, Pane, Node and Parent); but none of these classes has anything to do with the class Text! That's my problem – Joseph_Marzbani Jun 20 '20 at 02:12
  • Inheritance in CSS: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#introinheritance "CSS also provides for certain properties to be inherited by default..." and "The following properties inherit by default...": javafx.scene.Node, **javafx.scene.text.Text**, javafx.scene.text.Font. – Cem Ikta Jun 20 '20 at 12:19