How to make a simple Listbox in nifty?

Hi

This is a problem I can’t solve myself. I tried for about four hours, but I can’t get nifty Listbox to display items. It shows only srcollbars, but the items are there (I can tell it by counting them or dsplaying in System.out). In xml I have this:

[xml]<control id=“listBox1” name=“listBox” horizontal=“false” width=“50%” height=“30%” childLayout=“vertical” visibleToMouse=“true” displayItems=“10” forceSelection=“true”>

<panel id=“listBox1Data” width=“100%” childLayout=“vertical” visibleToMouse=“true”>

</panel>

</control>[/xml]

And in Java:

[java]

ListBox<String> mylist = niftymenu_nifty.getCurrentScreen().findNiftyControl(“listBox1”, ListBox.class);

mylist.addItem(“1”);mylist.addItem(“2”);mylist.addItem(“3”);mylist.addItem(“4”);mylist.addItem(“5”);

System.out.println(mylist.itemCount());

System.out.println(mylist.getItems().get(0));

[/java]

I hope that somebody can help me, because nifty tutorials are very messy. I’m using nightly JME and nifty.

The listbox you’re using is part of the old 1.2 Nifty library. It’s now used a bit differently.



You don’t really need the “data” part anymore. You just define the control that way in your XML (don’t forget to adjust your parameters for your game/app):



[xml]

<control type=“listBox” id=“youListBoxID” displayItems=“12” horizontal=“off” width="*" visibleToMouse=“true” forceSelection=“true” selectionMode=“Single” />

[/xml]



When you enter information the “old” way should work. In short, simply using the above in your screen layout definition should fix your issue.

Thank you :slight_smile:

I hope that Nifty tutorials will be a bit better with your contribution…