Nifty unique id with the prefix #

Hello, why the prefix # for unique id’s dont work if the element is created from code with an elementbuilder?

like PanelBuilder("#myId") <---- nifty says ints not unique.

but if ur setting the id in xml id="#myid" their is no problem.

The # is the sub-id prefix used especially for controls. When you have a controlDefinition and you need to access individual elements of that control you have a problem: You can’t give them a fixed “id” because when you apply the same control multiple times on the same screen then your unique id would not be unique anymore. sub-ids fix this. You give the element inside of your controlDefinition an id that starts with “#” (maybe “#actionButton”) and Nifty will later prefix this with the actual control id. If you add your control and give it the id “myCoolControl” then Nifty will create an element inside of that control with the id “myCoolControl#actionButton”.

It sounds more complicated than it is, really :slight_smile:

If used for controls then the # syntax should work as expected. The nifty-default-controls-example uses this without any warnings:

[java] new ControlDefinitionBuilder(NAME) {{

set(“childRootId”, “#effectPanel”);

panel(new PanelBuilder() {{



panel(new PanelBuilder("#effectPanel") {{








onShowEffect(builders.createMoveEffect(“in”, “left”, 500));

onHideEffect(builders.createMoveEffect(“out”, “right”, 500));





You can’t use “#” in a general element without confusing Nifty :slight_smile:

thx :), i will just wrap my Panel by a ControlDefinitionBuilder.