ListBox displays nothing

Hello I have a problem my listBox blank: / here is my code



[java]

ListBox listBox = nifty.getCurrentScreen().findNiftyControl("myListBox", ListBox.class);





listBox.addItem("b");

listBox.addItem("c");

[/java]

and my Xml



[xml]

<control name="listBox" id="myListBox" displayItems="4" color="#ffffff" horizontal="off" visibleToMouse="true" forceSelection="true" selectionMode="Single" y="140" width="90%"x="5%" height="50%" ></control>

[/xml]





nothing appears I have a list box empty



:confused: thanks

Try debugging it to make sure that listBox is not null when you try to add items to it.

[java]ListBox listBox = nifty.getCurrentScreen().findNiftyControl(“myListBox”, ListBox.class);





listBox.addItem(“b”);

listBox.addItem(“c”);

System.out.println(listBox);[/java]



I’ve



[java]de.lessvoid.nifty.controls.listbox.ListBoxControl@1ee9cbee[/java]



:confused:

iif I get the items I have “b, c” … it’s strange

When do you do that code? In the bind event?

an element of nifty call a function. But even if I put it in another class it does not work

help

Here is the URL to the default control - ChatControl. It should provide a decent example of how it can be done.

http://nifty-gui.git.sourceforge.net/git/gitweb.cgi?p=nifty-gui/nifty;a=tree;f=nifty-controls/src/main/java/de/lessvoid/nifty/controls/chatcontrol;hb=refs/heads/1.3.1

This is the Java code.



The XML code can be found here:

http://nifty-gui.git.sourceforge.net/git/gitweb.cgi?p=nifty-gui/nifty;a=blob;f=nifty-controls/src/main/resources/nifty-controls/nifty-chat-control.xml;h=2817999e9d8cbe14330112a9f46be933007b3ed6;hb=refs/heads/1.3.1