NiftyGui created from code issue

Hello @all,

if im creating a layout from code and adding it to the rootElement of a screen than the layout is visible with all its children, but

i cant get my hands on the children by calling getElementByName. And if i look into the created layout, its says, it has no chidren, but this cant be, they are visible on the display.



im using the latest NiftyGui src - code from the trunk.

When you’re using the latest 1.3 Nifty Build you should really use the Builder classes for this. Setting up elements and connecting them together correctly is - unfortunatly in the current Nifty versions - not trivial. This is best left to Nifty.



So you can either use the new Builder classes, like:



[java]Screen screen = new ScreenBuilder(“start”) {{

controller(new ControlsDemoScreenController()); // we use this class as the screen controller

layer(new LayerBuilder(“layer”) {{

backgroundImage(“background-new.png”);

childLayoutCenter();

panel(createListBoxDialog());

}});

…[/java]



to create the hierarchy or you can use the “old” way of creating dynamic elements using the Create* classes, like:



[java] CreateButtonControl createButton = new CreateButtonControl(“backButton”);

createButton.set(“label”, “Back to Menu”);

createButton.setAlign(“right”);

createButton.setInteractOnClick(“back()”);

createButton.create(newNifty, screen, screen.findElementByName(“buttonPanel”));[/java]



both ways are supported in Nifty 1.3 and should add the newly created elements correctly.