potato
potato

Reputation: 4589

adding the same actor multiple times to a table

I am using this code to place an actor multiple times horizontally in a table. When I run the code, only 1 appears. Why and how do I get around this?

private void createUI(){
        texture=new Texture("1.png");
        ImageButton.ImageButtonStyle fibs=new ImageButton.ImageButtonStyle();
        fibs.imageUp=new TextureRegionDrawable(new TextureRegion(texture));
        button1= new ImageButton(fibs);
        button1.setBounds(0f, 0f, texture.getWidth(), texture.getHeight());
        button1.setPosition(0, 0);
        scrollTable=new Table();
        scrollTable.setBounds(0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        scrollTable.setPosition(0,50);
        scrollTable.add(button1);
        scrollTable.add(button1);
        scrollTable.add(button1);
        stage.addActor(scrollTable);
    }

Upvotes: 2

Views: 614

Answers (1)

Xoppa
Xoppa

Reputation: 8123

An actor contains information about how and where it should be rendered as well as what should happen when you click on it etc. Therefor you can't add the same actor multiple times to the stage. If you want to have more than one button then create more than one button.

Upvotes: 1

Related Questions