I'm using LibGDX v1.1.0 and I see that the label of a TextButton is not properly centered. I have the following code:

m_resumeButton = new TextButton("resume", skin);
m_resumeButton.addListener(new ChangeListener() {
    public void changed(ChangeEvent event, Actor actor) {
        m_state = GameState.RUNNING;

The default TextButtonStyle is defined as:

"com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
    "default": {
        "up": "menu-button", 
        "down": "menu-button-down", 
        "checked": "menu-button-down", 
        "disabled": "menu-button-disabled", 
        "font": "font24", 
        "fontColor": "white"

The menu button images are simple 240x48 bitmaps saved as 9-patch images. An image can be found here to illustrate the problem:


Am I doing something wrong? Or is there a problem with the button images I'm using?

  • \$\begingroup\$ Using a non 9-patch image doesn't make a difference. The label is still not centered properly. \$\endgroup\$ – Kees de Bruin Jun 10 '14 at 11:40

To solve the alignment problem of the label text I found some information on the internet (where else?). It is possible to add some additional padding to the label inside the text button:

TextButton button = new TextButton(text, skin, styleId);
button.setSize(width, height);
// Add some padding to the label in the button to shift it up a bit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.