Daniel Piskorz
Daniel Piskorz

Reputation: 440

Centering multiple line text in JavaFX label

I'm struggling to center my multiple line Label in JavaFX.
I splitted each line using \n, and I can't center the whole text. I've been trying to use label.setAlignment(Pos.CENTER)but it just doesn't work.

Here is what I've got:
xxxxxxxxx
xxxxxx......
xxxx..........

this is what I need:
xxxxxxxxx
...xxxxxx...
.....xxxx.....

I know it has to be a better solution than filling labels with unnecessery spaces.

Upvotes: 6

Views: 2379

Answers (1)

Zephyr
Zephyr

Reputation: 10253

Don't use setAlignment. You don't want to just align the Label itself, but the text within it. Try setTextAlignment instead.

Upvotes: 12

Related Questions