Nifty + Listbox not showing

SO I am trying to get a list box showing and it is not working.

I can get text to show up though. Below is my XML any help is appreciated.

[xml]<?xml version="1.0" encoding="UTF-8"?>

<nifty xmlns="" xmlns:xsi=""


<!-- Your IDE now tells you that one <screen></screen> element is expected here, etc. -->

<screen id="start" controller="mygame.Main">

<layer id="layer" backgroundColor="#0000" childLayout="vertical">

<panel id="panel" height="100%" width="100%" align="center" valign="center" backgroundColor="#999999" childLayout="vertical" visibleToMouse="true">

<!–interact onClick="quit()"/–>


<onStartScreen name="fade" mode="in" length="300" startDelay="0" inherit="true"/>

<onEndScreen name="fade" mode="out" length="300" startDelay="0" inherit="true"/>


<control id="serverListBox" name="listBox" vertical="On" horizontal="off" align="center" valign="center" displayItems="10" selection="Single" />

<text id="text" font="aurulent-sans-16.fnt" color="#000f" text="Hello from jME3" align="center" valign="center" />

</panel >



<screen id="end">



You listbox has no data? What should it show?

Show us the code in your bind method.

As requested here is my code. As you can see I am calling a method called fillMyListBox(); to load the data.

Normen. If you look at any html form or mfc or sping, when you define a listbox it should show at least empty. So if Nifty does not do that by deault, good to know.

[java]package mygame;


import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.NiftyEventSubscriber;

import de.lessvoid.nifty.controls.ListBox;

import de.lessvoid.nifty.controls.ListBoxSelectionChangedEvent;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import java.util.List;


  • test
  • @author normenhansen


    public class Main extends SimpleApplication implements ScreenController{

    private Nifty nifty;

    public static void main(String[] args) {

    Main app = new Main();




    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Blue);



    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,




    nifty = niftyDisplay.getNifty();

    nifty.fromXml("Nifty/WorldServerListMenu.xml", "start",this);


    // attach the nifty display to the gui view port as a processor


    // disable the fly cam

    // flyCam.setEnabled(false);

    // flyCam.setDragToRotate(true);



    public void fillMyListBox() {

    Screen screen = nifty.getScreen("start");

    ListBox listBox = screen.findNiftyControl("serverListBox", ListBox.class);





  • When the selection of the ListBox changes this method is called.



    public void onMyListBoxSelectionChanged(final String id, final ListBoxSelectionChangedEvent<String> event) {

    List<String> selection = event.getSelection();

    for (String selectedItem : selection) {

    System.out.println("listbox selection [" + selectedItem + "]");



    public void bind(Nifty nifty, Screen screen) {

    System.out.println("bind( " + screen.getScreenId() + ")");


    public void onStartScreen() {



    public void onEndScreen() {



    public void quit(){




    public void simpleUpdate(float tpf) {

    //TODO: add update code



    public void simpleRender(RenderManager rm) {

    //TODO: add render code




Well does it work now? Theres also an example template for listbox in the SDK. Press File->New and select the template under “GUI”.

by the way you should initialize your listBox in bind() method.

It is still not working :frowning:

Thanks Normen, I did not see a listbox option under there though, however that is a cool feature.

glaucomardano, Can you please explain what you mean by a bind() method?

Try moving the call to fillMyListBox to the bind method. Normally, I fill my listboxes in the bind method of my screen controller.

Oh, and store a reference to your listbox in a class variable. This is a lot faster then looking up the listbox each time you need it.


If I can find the time, I can check your code tonight when I get home, if you want. In preperation to that, do you see any errors in your log when running this code?

Okay, I moved it to the bind.

I set a break point and my listbox is still null after adding the 2nd item?

No, There are no errors running the code.

Here is the code from the nifty-default-controls-examples project:;a=blob_plain;f=nifty-examples/src/main/java/de/lessvoid/nifty/examples/defaultcontrols/listbox/;hb=refs/heads/1.3.1

This is a general screencontroller used with a listbox. It has a bit of extra stuff in there as well, since the example has a few text fields and buttons besides the listbox. But it should show you how to do the whole listbox setup / adding of items.

Figured it out through trial and error!

I needed to add:


<useStyles filename="nifty-default-styles.xml" />

<useControls filename="nifty-default-controls.xml" />[/xml]

to my xml… since I had no default controls… Thanks ffor your help.




Gotta love when it is the simplest thing.

Ah yes, that would help…

Should have seen that

Thats what happens when you start with a basic tutorial and want to add objects in. Oh well Im rocking nifty now got a few interactive pages done!

Cool, gratz

and if you run into any problems let us know.

And if you have any controls you would like to see added to the default control, you can also let us know and me and Void will see what we can do.

I did a progress bar control with horizontal and vertical direction :), and with text too :). But the just render the text horizontally:

EDIT: Ops, this image doesn’t has text, I’m gonna change this image.

That’s it :):

Could you use an image instead of text?

An ugly hack would be to create a new line for each letter







Yes, it’s possible to use image, but I want to do it dinamically, because the text might be changed. e.g.: COMBO - 30. SCORE - 70000.

And about keeping blank spaces between the letters doesn’t work. The only way is to create a new label control and a new text renderer (Or adapt the existing ;)).