Can't populate ListBox?

Hello. I’ll get straight to the point - I can’t populate the ListBox nifty gui panel with any data. I tried several other solutions presented in this forum but I still can’t seem to get it to work. The class that implements this GUI is an extension of abstractAppState class. Can anyone see anything wrong with this code?


<?xml version=“1.0” encoding=“UTF-8”?>


<useControls filename=“nifty-default-controls.xml” />

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

<screen id=“start”>

<layer id=“background” childLayout=“center”>

<image filename=“Interface/underground-background.jpg”></image>


<layer id=“layerWithButtons” childLayout=“center” height=“75%”>

<panel id=“panelTop” height=“75%” width=“500px” align=“center” valign=“center” childLayout=“center” visibleToMouse=“true”>

<control id=“myListBox” name=“listBox” horizontal=“false” width=“75%” height=“100%” childLayout=“vertical” visibleToMouse=“true”>

<panel id=“myListBoxData” width=“100%” hwight=“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” />






<screen id=“end”>




and my Java looks like this:


package views;





import com.jme3.asset.AssetManager;


import com.jme3.bullet.BulletAppState;

import com.jme3.font.BitmapFont;

import com.jme3.font.BitmapText;

import com.jme3.input.FlyByCamera;

import com.jme3.input.InputManager;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Node;

import com.jme3.system.AppSettings;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.controls.ListBox;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;



  • @author pawelgasiorowski


    public class StartScreen extends AbstractAppState implements ScreenController {

    private SimpleApplication app;

    private Node rootNode;

    private AssetManager assetManager;

    private AppStateManager stateManager;

    private InputManager inputManager;

    private ViewPort viewPort;

    private BulletAppState bullet;

    private Node guiNode;

    private AppSettings appSettings;

    private AudioRenderer audioRenderer;

    private BitmapFont guiFont;

    private BitmapText hudText;

    private FlyByCamera flyByCamera;

    private int number = 0;


    public void initialize(AppStateManager stateManager, Application app) {

    super.initialize(stateManager, app); = (SimpleApplication) app;

    this.rootNode =;

    this.assetManager =;

    this.stateManager =;

    this.inputManager =;

    this.viewPort =;

    this.guiNode =;

    this.audioRenderer =;

    this.flyByCamera =;

    // nifty experiment

    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

    assetManager, inputManager, this.audioRenderer, this.viewPort);

    * Create a new NiftyGUI object /

    Nifty nifty = niftyDisplay.getNifty();

    * Read your XML and initialize your custom ScreenController */

    nifty.fromXml("Interface/screen.xml", "start");


    // nifty.fromXml("Interface/helloworld.xml", "start", new MySettingsScreen(data));

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


    // disable the fly cam




    // SimpleUpdate


    public void update(float tpf)



    public void bind(Nifty nifty, Screen screen) {

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





    public void onStartScreen() {


    public void onEndScreen() {




    Any help most appreciate it!

Why do you have a panel inside your list box? I use controls and add items programmatically with no problems but I don’t have any extra stuff inside the list box declaration. (Actually now all the list boxes are created using builders but we did use to have some created from XML and it worked the same).

Hey zarch - thanks for the reply. I’m fairly new to jmonkey and nifty gui so please bear with me ^_^’. I’ve removed the panel from the list box just like you suggested - but still couldn’t get this to work. I can see the panel with two scrollbars but without any items inside it… Can you provide some sample code how would you do it “programatically”? This is what I have atm:

Actually, zarch I’ve done it - thanks for the hint :wink:

Cool, glad it helped. :slight_smile:

Populating Listboxes from XML or from Builder was supported some time ago but is not anymore. You can only add items dynamically from Java using the Listbox API. This is because now the ListBox directly supports your own custom instances, e.g. you can add your own whatever object directly if you want. And this was not possible with XML/Builder anymore so support for this has been dropped.

1 Like

Yes, I drop my own objects into the list, very useful :slight_smile: