LibGDX Scroll Pane of buttonGroup

784 views Asked by At

I am trying to create my own tile map creator, so I need some panel where user can choose between textures. I wanted to create scrollpane inside my camera view. It moves perfectly and everything is working with List of Strings but if I want to change Strings to buttonGroup it only displays in my scrollpane "com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup@5dcff25d" nothing else only one row with this. Here is my code:

private void initPanel(){
    skin=new Skin(Gdx.files.internal("uiskin.json"));

    background = new Group();
    background.setBounds(0, CAM_HEIGHT-PANEL_SIZE, PANEL_SIZE, PANEL_SIZE);

    stage=new Stage(new ScreenViewport());
    list=new List<ButtonGroup>(skin);

    buttons=new TextButton[TEXTURE_NUMBER];
    buttons[0]=new TextButton("Delete",skin);
    buttons[1]=new TextButton("Red",skin);
    buttons[2]=new TextButton("Blue",skin);
    buttons[3]=new TextButton("Green",skin);

    buttonGroup=new ButtonGroup<TextButton>(buttons);
    buttonGroup.setMaxCheckCount(1);
    buttonGroup.setMinCheckCount(0);
    list.setItems(buttonGroup);

    scrollPane=new ScrollPane(list);
    scrollPane.setBounds(0, 0, PANEL_SIZE, PANEL_SIZE);
    scrollPane.setPosition(0,CAM_HEIGHT-PANEL_SIZE);
    scrollPane.setTransform(true);

    stage.addActor(background);
    stage.addActor(scrollPane);
    background.addActor(new Image(new Texture("textures/panel_background.png")));
    Gdx.input.setInputProcessor(stage);
}
1

There are 1 answers

2
John On BEST ANSWER

Whenever you see something like com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup@5dcff25d or package.class@hexstring, it means that somebody is trying to convert the object into a string by calling Object#toString().

In this case the culprit is List class- which is designed to take a bunch of objects and display them as text. ButtonGroup is intended to associate the buttons logically instead of position them on the screen, so you'll need to create the ButtonGroup and a Table. Add the buttons to both, and then put the table into the ScrollPane.

I'm assuming of course you need the ButtonGroup functionality to manage the buttons. If the buttons are independent of each other, then you can skip the ButtonGroup entirely and just add the buttons to the table.