0
votes

I'm having issues getting libgdxs scrollpane control to work. The code below shows control setup for a simple layout with a label, a List of items inside a scrollpane, and a button. The problem is my scroll pane doesn't show anything other than the vScroll/vScrollKnob ninepatch (that tiny white square) it just looks like this:

screenshot.

        private void setupLayout()
{
    String[] listEntries = {"1","2","3","4","5"};
    ListStyle listStyle = new ListStyle();  
    NinePatch example = new NinePatch(new Texture(Gdx.files.internal("data/example.9.png")));       
    listStyle.selectedPatch = example;
    listStyle.font = new BitmapFont();
    mList = new List(listEntries,listStyle);

    ScrollPaneStyle paneStyle = new ScrollPaneStyle();
    paneStyle.vScroll = example;
    paneStyle.vScrollKnob = example;        
    mListScroll = new ScrollPane(mList,paneStyle);
    mListScroll.setScrollingDisabled(true, false);
    mListScroll.width = 500;
    mListScroll.height = 500;

    LabelStyle ls = new LabelStyle();
    ls.font = new BitmapFont();
    ls.fontColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
    mLabel = new Label("Label", ls);    

    TextButtonStyle buttonStyle = new TextButtonStyle();
    buttonStyle.font = new BitmapFont();
    mButton = new TextButton("Button",buttonStyle);

    Table table = new Table();
    table.add(mLabel);
    table.row();
    table.add(mButton);
    table.row();
    table.add(mListScroll);
    mStage.addActor(table);
}

It works as expected if i don't user the scroll pane and add the list directly to the table like this:

    Table table = new Table();
    table.add(mLabel);
    table.row();
    table.add(mButton);
    table.row();
    table.add(mList);             //changed mListScroll(scrollpane class) to mList(List class)
    mStage.addActor(table);

screenshot

But then it will extend out the bottom of my screen when there are too many items. What am I doing wrong here? Is there another parameter i need to set on the scrollpane?

1

1 Answers

1
votes

I believe the issue you are having is how you are adding things to the table. I would suggest the following code instead of how you are doing it:

Table table = new Table();
table.add(mLabel);
table.row();
table.add(mButton);
table.row();

// Changing the table layout size itself.
table.add(mListScroll).size(500, 500);

mStage.addActor(table);

For more a more detailed explanation refer to TableLayout the quick start here shows you more how using tables for laying out objects.