Search code examples
libgdxlibktx

ScrollPanel in libgdx (libktx)


I have a scrollpanel test headers in it. Through debug, I see that the panel itself is there, but the content is not displayed in it, although it seems to be. Maybe someone knows how this is possible? The panel itself adjusts to the size of the table, but the table itself, with the content inside, is not visible.


Solution

  • I found the root cause of the issue - you incorrectly added the actors to the stage, which resulted in Window's and ScrollPane's Stage to be null. You have to change this line in GameManager:

    screen.rootStage.actors.add(inventoryWindow.window)
    

    To this line:

    screen.rootStage.addActor(inventoryWindow.window)
    

    While your approach did add the actors to the Stage, they were not added to the root Group and their Stage variable was not set, which resulted in weird bugs like this one. Always prefer to use the public API methods instead of accessing the class variables directly.

    About pinpointing the issue: if you look into the ScrollPane rendering code, you'll notice that it only renders it children if clipBegin returns true. If you dig deeper, clipBegin has this particular check that prevented the children from being drawn: if (stage == null) return false;. Basically, you cannot use a ScrollPane without a Stage.