I'm having trouble showing a simple custom VerticalGroup.

Here's my SideBar class:

public class SideBar extends VerticalGroup {
    final GameManager gameManager = GameManager.instance;
    final Image nextBackground;
    final Image nextImage;
    final Image powerImage;
    final Image powerUp1Background;
    final Image powerUp2Background;
    final Image powerUp3Background;

    public SideBar() {
        nextBackground = new Image(gameManager.getTexture("bar.next.png"));
        nextImage = new Image(gameManager.getTexture("label.next.png"));
        powerImage = new Image(gameManager.getTexture("label.power.png"));
        powerUp1Background = new Image(gameManager.getTexture("powerup.bg.png"));
        powerUp2Background = new Image(gameManager.getTexture("powerup.bg.png"));
        powerUp3Background = new Image(gameManager.getTexture("powerup.bg.png"));

And here's where I add it to my main Stage:

    TopBar topBar = new TopBar();
    topBar.setY(DonutsGame.WORLD_HEIGHT - topBar.getHeight());

    SideBar sideBar = new SideBar();
    Gdx.app.log(TAG, "side bar - x,y: " + sideBar.getX() + "," + sideBar.getY() + ", w,h: " + sideBar.getWidth() + "," + sideBar.getHeight());

My TopBar class extends Group and is displaying correctly, so I'm not sure what I'm doing wrong with SideBar that's causing it to not show.

The log output shows that the position, and width/height are all 0, which seems incorrect to me according to the vertical group's documentation. Which states that the width/height should be based on the pref. width/height of the children (height based on sum).

I've tried calling validate and layout with no success.

  • \$\begingroup\$ If I manually set the width and height, then the group shows, and I just re-read the documentation. It actually says preferred width/height are based on children. However, the examples I can find don't say anything about having to set the width and height. \$\endgroup\$
    – Townsfolk
    Commented Jun 21, 2016 at 22:45

1 Answer 1


It seems that if the VerticalGroup is added to another layout, then it works. Looking at the code, this is due to VerticalGroup also being a Layout, and so it's prefWidth/Height are used instead of the getWidth/Height methods.

I got around this by manually setting the size to the pref. size.

setSize(getPrefWidth(), getPrefHeight());

Note, that you don't need to do this if you're putting the VerticalGroup in another WidgetGroup like Table or ScrollPane since they use prefWidth/Height anyway.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .