hi guys
i am troubled with nifty again
[java]
ListBoxControl saveC = new ListBoxControl();
this.saveC = screen.findControl(“save”, ListBoxControl.class);
this.saveC.addItem(“Hallo”);
[/java]
[xml]
<screen id=“showSave” controller=“project.Menu_Controller”>
…
<control id=“save” name=“listBox” horizontal=“false” width="*" height=“100%” childLayout=“vertical” visibleToMouse=“true”>
<panel id=“saveData” width=“100%” childLayout=“vertical” visibleToMouse=“true”>
<label text=“Static Item I” style=“my-listbox-item-style” />
<label text=“Fo Shizzle” style=“my-listbox-item-style” />
<label text=“Static Item III” style=“my-listbox-item-style” />
<label text=“Static Items ftw” style=“my-listbox-item-style” />
</panel>
</control>
…
[/xml]
this throws a nullpointer-exception cuz nifty cant find this control dunno what i did wrong…
the listbox itself on the screen, but not the elements of the list… thats odd too…
in another topic it is said, that there must be a child with “Data” appended within the id of the control… but that didnt work either…
any clue? any hints?
thx in advance
Terry
Cause it’s not ListBoxControl.class but ListBox.class (I think). I did this at home yesterday and it somewhat worked. But since I haven’t committed that code to SVN yet, I can’t check it on my SVN server.
Hi,
Its probably because of this :
[java]ListBoxControl saveC = new ListBoxControl();
this.saveC = screen.findControl(“save”, ListBoxControl.class);
this.saveC.addItem(“Hallo”);[/java]
It should be either
[java]saveC = new ListBoxControl();
this.saveC = screen.findControl(“save”, ListBoxControl.class);
this.saveC.addItem(“Hallo”);[/java]
or
[java]ListBoxControl saveC = new ListBoxControl();
saveC = screen.findControl(“save”, ListBoxControl.class);
saveC.addItem(“Hallo”);[/java]
Though I might be wrong about that. It works for my little testcase.
I think the items in your list won’t show up because of
style="my-listbox-item-style"
Check your style, delete it or change it to
style="nifty-listbox-item"Then it should work as well.
I get the same problem here.
I’m not using a dynamic ListBox creation.
[java]
private boolean fillListBox(Star star) {
ListBoxControl lBox = nifty.getCurrentScreen().findControl(“stellarBodiesBox”, ListBoxControl.class);
if (!star.getSolarSystem().getPlanets().isEmpty()) {
lBox.addItem(star.getSolarSystem().toString());
lBox.addItem(star.toString());
for (Planet p : star.getSolarSystem().getPlanets()) {
lBox.addItem(p.toString());
System.out.println(“Filled.”);
}
} else {
lBox.addItem(star.getSolarSystem().toString());
lBox.addItem(star.toString());
}
return true;
}
[/java]
Anyone found a working fix?
Yay. Just found the problem.
In your xml, you have to add a part where the “data” will be added. You need the |control| definition AND a child panel where you’ll add the “items”.
Here’s how it looks:
[xml]
<panel id=“listBoxPanel” align=“center” valign=“top” childLayout=“horizontal” visibleToMouse=“false”>
<control type=“listBox” id=“stellarBodiesBox” displayItems=“8” horizontal=“false” selectionMode=“Disabled”>
<panel id=“stellarBodiesBoxData” width=“100%” childLayout=“vertical” visibleToMouse=“true”>
</panel>
</control>
</panel>
[/xml]
This works here.