Libgdx – TextButtons added to Table – clicklistener not working [closed]


I am having issues trying to implement a menu in a previously created game. I am pretty new to Libgdx and not sure how everything works just yet. I am adding a menu to an already created game scene using a table and text buttons.

My goal:

  1. Click button which shows table full of buttons
  2. Click specific table button and do something with them
  3. Click away from the table area then table/buttons will disappear

I’ve got it all working except connecting the buttons to clicklisteners. I can only think of the buttons not actually being on the top surface where you can click them.

Section of code: Shortened for brevity; class implements InputProcessor

    protected MenuComponent(GameContext context, SeaBattleScene owner) {         super(context, owner);         this.context = context;     }      @Override     public void create() {         batch = new SpriteBatch();         this.stage = new Stage();         Gdx.input.setInputProcessor(stage);         menuUp = new Texture("assets/ui/disengage.png");         menuDown = new Texture("assets/ui/disengagePressed.png");         menuWindow = createMenuWindow();         menuWindow.setVisible(false);         stage.addActor(menuWindow);         stage.getRoot().setPosition(65,150);     }      @Override     public void update() {     }      @Override     public void render() {         batch.begin();         batch.draw((menuButtonIsDown)?menuDown:menuUp, MENU_buttonX, MENU_buttonY);         batch.end();         stage.act();         stage.draw();     }     private Table createMenuWindow() {         //Table View         Table table = new Table();         table.setPosition(675,160);         //Button View         SpriteDrawable upFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable downFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable checkedFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         TextButtonStyle buttonStyle=new TextButtonStyle(upFormat, downFormat, checkedFormat, new BitmapFont());         //Individual Buttons         TextButton lobbyButton = new TextButton("Back to Lobby",buttonStyle);         lobbyButton.addListener( new ClickListener() {                           public void clicked(InputEvent event, float x, float y) {                 System.out.println("Clicked");             };         });         TextButton mapButton = new TextButton("Show Maps",buttonStyle);         table.add(lobbyButton).pad(3,0,3,0).row();         table.add(mapButton).pad(3,0,3,0).row();         return table;     }           public static Texture createRoundPixMap(Color color, int width,             int height, int cornerRadius) {         Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.Alpha);         pixmap.setBlending(Pixmap.Blending.None);         pixmap.setColor(color.r,color.g,color.b,0.4f);         pixmap.fillCircle(cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillCircle(cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillRectangle(0, cornerRadius, width, height - (cornerRadius * 2));         pixmap.fillRectangle(cornerRadius, 0, width - (cornerRadius * 2), height);         Texture texture = new Texture(pixmap);         pixmap.dispose();         return texture;     } 

Can someone expain or show me what I am doing wrong, so I can fix it to where I can use the buttons?

This is basically what it looks like: Menu