I have an inventory UI which is a table in scene2d. Then the table had a bunch of Containers which are basically inventory slots. They have a transparant grey background color. Then in each container is an ItemStack with a picture of an item and a stacksize. When I pull this ItemStack over a container that was created later, it moves behind the container and the transparant grey background will be in front of the item picture. How do I temporarily (or permanently) move it to the foreground so it doesn't matter in front of which container I drag the item?

Example of what happens: https://i.imgur.com/yq4njex.gifv

This is how I create the containers:

// Create inventory slots
for (int i = 0; i < inventory.getInventorySize(); i++) {
    if (i % SLOTS_PER_ROW == 0) table.row();

    Container cont = new Container();
    cont.background(Utils.createDrawable(1, 1, new Color(0, 0, 0, 0.4f)));


After that I add each ItemStack to the list of containers/inventoryslots like this:

// Add ItemStacks from Items to their respective slot
ArrayList<Item> items = inventory.getItems();
for(Container slot : inventorySlots) {
    Item item = items.get(inventorySlots.indexOf(slot));

    if(item != null) {
        ItemStack itemStack = new ItemStack(item);
        addInventoryEvent(itemStack, items);

1 Answer 1


The ZIndex of an Actor describes its position in respect to its siblings (other Actors in the same Group)

you can manipulate it with Actor.setZIndex(). There are also convienience methods for your usecase: Actor.toFront() and Actor.toBack()

The Group class has methods to add Actors in front or behind another Actor. It can allso swap the ZIndex of two of its children.

  • \$\begingroup\$ Yeah, this works. Thanks. However if the item needs to be drawn above another stage (Say the hotbar) and this stage is drawn later, I think there is no way to do this. Currently I'm using a flag that determines whether the hotbar or inventory should be drawn first, but I might consider not having multiple stages, but just edit 1 big stage. \$\endgroup\$
    – TJRC
    Apr 8, 2020 at 14:04

You must log in to answer this question.

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