I am making a simple gui in libgdx and run into this problem ; when you click on the button it's bounds (?) are wrong since if I click under it, the game registers it as a click.

On the other end, if I click it at the top it won't get the click. It seems like the bounds are a bit under the button. I tried to set manually but nothing.

Also i tried changing sizes.

Looked here : too this is almost the same but no answer..

tabl = new Table();
    stage =new Stage();
    tabl.setSize(stage.getWidth()/2, stage.getHeight()/2);
    tabl.defaults().size(500, 40);

    g = game;


    skin = new Skin(); 

    TextureAtlas te = new TextureAtlas(Gdx.files.internal("uiskin.atlas")); 

    skin.add("default-font", new BitmapFont());

    Pixmap r = new Pixmap(100,100,Format.RGBA8888);

    r.fillRectangle(1, 1, 13, 13);
    Texture s = new Texture(r);
    SpriteDrawable s1 = new SpriteDrawable(new Sprite(s));

    TextButton gam = new TextButton("new games",skin);

    gam.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            // TODO Auto-generated method stub
            new Logger("e").setLevel(10);
            return true;

    LabelStyle tt = new LabelStyle(new BitmapFont(), Color.BLUE);
    Label l = new Label("d",tt);



  • \$\begingroup\$ You have table.setDebug(true) is the button being drawn inside the correct cell? And does gam.setDebug(true) generates a debug rectangle exactly over the button? \$\endgroup\$
    – Madmenyo
    Jul 30, 2015 at 18:09
  • \$\begingroup\$ Yes. Red border. \$\endgroup\$
    – SPL
    Jul 30, 2015 at 18:10
  • \$\begingroup\$ I take it you are having stage.draw and stage.act in some update method without anything else going on there that could effect it? What if you initialize the stage like this stage = new stage(new ScreenViewport()). \$\endgroup\$
    – Madmenyo
    Jul 30, 2015 at 18:13
  • \$\begingroup\$ it is in a render method. \$\endgroup\$
    – SPL
    Jul 30, 2015 at 18:15
  • \$\begingroup\$ Tried it almost the same. The bottom is 2 pixels wrong \$\endgroup\$
    – SPL
    Jul 30, 2015 at 18:16

1 Answer 1


Not exactly sure what is going but I always create a stage with a viewport (with or without a camera). Something like this:

stage = new Stage(new ScreenViewport());

table = new Table();
table.alight(Align.top | Align.center);
table.setFillParent(true); //To have it fill the screen

TextButton button = new Button("Click me", skin);
button.addListener(new ClickListener()
     public void clicked(InputEvent event, float x, float y)
          system.out.println("You clicked me!")



I did not test the above but it should create a table with a button at the top of the screen. The bounds should be perfect as well. Try it, there is not much code and recreate it step by step. If the code above does not work let me know, sometimes this scene2D stuff gives me headaches too :).

  • \$\begingroup\$ Still the same. Everything seems fine but this \$\endgroup\$
    – SPL
    Jul 30, 2015 at 18:48
  • \$\begingroup\$ @SPL With my code the button is offset? \$\endgroup\$
    – Madmenyo
    Jul 30, 2015 at 18:49
  • \$\begingroup\$ Yes but finally found it! I manually set the viewport with a gl command and somehow it made this \$\endgroup\$
    – SPL
    Jul 30, 2015 at 18:50
  • \$\begingroup\$ I bet what you found was not in your supplied code. ;) \$\endgroup\$
    – Madmenyo
    Jul 30, 2015 at 18:50
  • \$\begingroup\$ I'm curious what the gl command was. \$\endgroup\$
    – Madmenyo
    Jul 30, 2015 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .