Nifty: Problem with accessing a Nifty control on a popup


My problem is the following:

On one of my GUI’s popups there’s a DropDown and I want to add content to that DropDown before the popup is shown (so that it already has content when the popup opens for the first time).

However, doing the following doesn’t work:

[java]nifty.showPopup(nifty.getCurrentScreen(), createNewGamePopup.getId(), null);

mapSelection = nifty.getCurrentScreen().findNiftyControl(“mapDropDown”, DropDown.class);



Nifty doesn’t find the control “mapDropDown” in this case. My guess is that the first command isn’t completely executed yet (so the popup isn’t completely loaded) when the second command is executed, so it obviously can’t find the control I’m looking for.

Any clue what I can do here? Is there a way to access the DropDown and add stuff to it before I show the Popup it’s on?

I tried it with nifty.getScreen(>name of my popup<).findNiftyControl(“mapDropDown”, DropDown.class); as popups are on the same level as screens in the XML definition, but that doesn’t work.

Thanks! :slight_smile:

You can check when the popup is created in update loop, you can make your screen controller as an app state, and when the popup is created, you can finally modify it. But before, see if this does find the control:


nifty.getScreen("myscreen").findControl("mydropdown", DropDownControl.class);


Also, make sure your poupup and your drop down has their ids set.

That doesn’t work unfortunately. Thanks though!

However, I just found out the solution:

After instantiating the popup, I can just access it with popup.findNiftyControl(…) and add the content to the DropDown :slight_smile: I’m stupid