Search code examples
javafxfxmldesktop-application

How to align text inside a spinner to center in javafx?


I have two spinners that show time in hrs and mins each. However I would like to have the numbers show up in the center of its textfield.screenshot_of_current_state.

Also its not an android app. Its a normal javafx based desktop app.(I'm saying this cause other similar questions are based around android and xml's)

Also I'm new around here and to programming as a whole. So I could be wrong about some things.


Solution

  • SpinnerValueFactory<Integer> factory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 23);
    Spinner<Integer> hoursSpinner = new Spinner<>(factory);
    hoursSpinner.editorProperty().get().setAlignment(Pos.CENTER);
    

    The editor property wraps a TextField.
    TextField has an alignment property.