arun
arun

Reputation: 368

JavaFX Spinner - How to align the text inside the spinner if the arrows are on left and right?

So I have this Spinner which is used for pagination. Its style class looks like below:

Spinner<Integer> spinner = new Spinner<>(1,20,1);
spinner.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL);

So now the spinner appears with arrows on the left and right sides of the number. However, the text is aligned to the left of the spinner always. Say even if I have some width for the spinner (ex. 200px or something) the number displayed in the spinner is always next to the left arrow. I would like to know how to set it to the center of the Spinner.

This is what I tried in CSS:

.spinner > .text-field
{
    -fx-text-alignment: center;
}

.spinner
{
    -fx-text-alignment: center;
}

.spinner > text
{
    -fx-text-alignment: center;
}

Nothing worked.

Upvotes: 1

Views: 285

Answers (1)

James_D
James_D

Reputation: 209339

You need

.spinner > .text-field
{
    -fx-alignment: center;
}

The -fx-text-alignment property determines how multi-line text is aligned (i.e. the alignment of one line of text relative to another line). To align overall content, use -fx-alignment.

Upvotes: 2

Related Questions