I have been searching the forums for how to dynamically update my GUI during run time. I have found good info on how to add elements dynamically, but I haven’t found things about how to remove elements or possibly make them not visible any longer.
The scenario is that I have a status panel in my GUI and if I select a tile in my game I want to draw various elements(buttons, labels…ect) based on the type of tile the user selects.
This means I would like to remove all current existing elements in the panel and build up a new one.
Anyone have any suggestions about if this is possible?
Short questions:
Can you remove elements dynamically
Can you make existing elements no longer visible or disable them somehow.
As myamo said you can remove them. If your layout makes trouble, navigate to the parent-element of the element you have removed and call a method that should be something like “layoutElements” or “refreshLayout”. Then the elements of this particular parent-element are rearranged.
Hi guys,
A wierd issue I am facing while removing elements and adding elements.
I have a panel with 20 elements and I want to remove them all and another 20 elements.
I have written an Controller implementation for this panel. Below is the code from that class
public void removeChildren(){
for(int i=0; i<element.getElements().size(); i++){ ///this has 20 size
element…getElements().get(i).markForRemoval();
}
//call to layout elements
element.layoutElements();
}
Now that panel is empty.
However later when I add another 20 items to that panel. It never shows on the screen
However, printing its getElements().size() gives 20 elements.
I am not sure where I am missing something to get this working.
Well, the addition is immediately after I delete the elements.
Also, I implemented the EndNotify interface and actually added the new elements only after all the elements have been removed by nifty, which we get in the following method
public void perfor() — of the EndNotify interface.
Still, in this case also the new elements are not visible, though they are actually there in the panel.
Sorry, i m at office now, I will post the code once I get home, Thanks