Search code examples
libgdxscene2d

How do you align text on a Text Field?


I made a TextField using Libgdx scene2d and I want the text on the text field to appear on the center, so when the user type a string, the string will start at the center and not at the left. I also tried to set the cursor position but nothing is happening, is it because it's in a table?

textField = new TextField("", tfStyle);
textField.setCursorPosition(33);
table.add(tf);

Solution

  • You can try textField.setAlignment(Align.center);.

    setAlignment(int alignment)

    Sets text horizontal alignment (left, center or right).