Nifty toggle panel/listbox visibility


I started yesterday Nifty gui and got a listbox working. Fill with data, remove the data, select, etc.

But I couldn’t solve this simple thing - toggle it’s visibility status? Found things like setEnabled, or deactivate the screen etc. but nothing didn’t work properly.








Oh great. Thanks :slight_smile:

Keep in mind that hiding an element this way still claims the space for it.

If you want to use that space for something else, you will need to remove the element from the stack altogether.

If this is what you want, I can give you an extended example on how to do that later tonight.

@ractoc: Is this the method : markForRemoval() ?

That’s the one…

And after that one you need to do a .layoutElements() as well. This actualy removes it because it re-layouts the elements.

I’m actually having elements with id confliting. I create a layer in source code with a predefined id. Then if I try to remove it with the markForRemoval() method, that layer is still attached to the screen. Then if I create a new layer with the same id, they have conflicts, and the new layer isn’t showed up. I did a test to testify the issue, as you can see below, the findElementByName() finds the “removed” element.


String id = mb.getElement().getParent().getId();



System.out.println("xD "+getScreen().findElementByName(id));


Nevermind, that wasn’t the problem why the new layers weren’t being displayed, fixed that. Btw, the code above doesn’t lie.

hhmmzz… never tried this with complete layers before, just with panels…

With panels it works a treat.

but if you are removing the entire layer, why not just have 1 layer and remove the top most panel? This would work. I’ve done this before. And it would mean you don’t have to create a new layer every time. Always remove as little elements as possible since removing and adding elements is costly.

No, I really need creating layers in the HUD screen, because the layers I’m creating in runtime are the move bar layers, then they have to overlay the rhythm track. Panels doesn’t overlay each other. As you can see, each red ball (move bar) have itself layer, and they overlay the top layer, where is the grey panel (rhythm track). Also, each move bar might overlays another, if their times are near. The output still shows id conflicts, but it’s working.

With complete layers hide and setVisible should work well enough. Since there’s no problem with elements taking up space needed for other elements there.

Oh, and you might also need to toggle the mouse visibility.