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);
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With