0

At the moment I have a piece of text defined with Text in my FXML. It is also located inside a TextFlow which is inside a ScrollPane. I have tried aligning the text to center in the FXML itself and in css but still doesn't seen to be working. Here is the FXML

<ScrollPane fx:id = "scrollPane">
     <content>
         <TextFlow styleClass="txtFlow">
               <children>
                    <Text styleClass="h1" text="Title" textAlignment="CENTER"/>
                    <Text styleClass="h2" text="&#10;Subtitle"/>
              </children>
          </TextFlow>
    </content>
</ScrollPane>

And here is the CSS

.h1{
-fx-font-family: "Helvetica";
-fx-font-size: 50px;
-fx-fill: #147cb0;
-fx-underline: true;
-fx-alignment: center; }
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
Josh Beaver
  • 127
  • 8
  • 18

2 Answers2

1

To align texts in TextFlow use

<TextFlow textAlignment="CENTER"> .... </TextFlow>

To align the content of ScrollPane use

<ScrollPane fx:id = "scrollPane" fitToWidth="true"> .... </ScrollPane>
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
1

Adding to @Uluk's answer, you can also achieve this using css by using the style on the TextFlow.

<TextFlow style="-fx-text-alignment: center;">

You can also get the desired effect by using a css file and a styleclass in it.

<TextFlow styleClass="txtFlow">

and on the css file as,

.txtFlow {
    -fx-text-alignment: center;
}
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176