Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The rule "-fx-text-alignment" doesn't work?

I'm creating a simple user interface with JavaFX, where some labels showing texts are used. I tried to move text to the center of labels with the rule:

-fx-text-alignment: center

yet it doesn't work and text is still located on the left by default. I have also checked that I haven't used any other rules that could override this. Any ideas? Here is the css code:

#subtitle
{
    -fx-font: bold italic 18pt "Arial";
    -fx-text-alignment: center;
    -fx-effect: dropshadow( one-pass-box, black, 8, 0.0, 2, 0 );
    -fx-text-fill: #1ebd1e;
}

Java code:

Label title = new Label("Trees");
title.setId("subtitle");
grid.add(title, 0, 0, 2, 1);

enter image description here

like image 320
Oscar Avatar asked Dec 01 '22 14:12

Oscar


1 Answers

I have the same problem.

The text in the label cannot be centered or right aligned, or ... nor in CSS nor in code like mylabel.setTextAlignment(TextAlignment.Center) when the label is larger than the text.

I use instead mylabel.setAlignment(Pos.CENTER) to solve the problem; also works in CSS with -fx-alignment:center;

like image 145
maurille Avatar answered Dec 04 '22 04:12

maurille