Nifty Gui Help

Hi Guys,

I seem to be strugling my way through trying to workout how to use nifty-gui. It seems really troublesome when there appears no javadoc or full api spec.

Currently I`m trying to workout how to clear the screen after screen transitions.

One screen has a fullscreen backdrop, the other does not.

When I transition between screens (from fullscreen to the other), the fullscreen backdrop still displays.

I have tried the following in the screenController when I click on a particular button.


nifty.getNifty().fromXml("main.xml", "mainLogin");



However I get the following exception thrown.


SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]



Does anyone happen to know how I can achieve what I am attempting (to clear/flush the screen between transitions)?


How are you setting the background?

I had exactly the opposite problem. I wanted the same background on every screen in my main menu setup but ended up including the background as a layer on every screen.

Edit: also… do you have the stack trace for the concurrent mod exception?

The background is simply set as a panel with length/width = 100% like follows


<panel id="backdrop" height="100%" width="100%" backgroundColor="#f60f" childLayout="horizontal" visibleToMouse="true">


The full stacktrace is as follows:


SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at java.util.AbstractList$Itr.checkForComodification(

at java.util.AbstractList$

at com.jme3.niftygui.InputSystemJme.forwardEvents(

at de.lessvoid.nifty.Nifty.render(

at com.jme3.niftygui.NiftyJmeDisplay.postQueue(

at com.jme3.renderer.RenderManager.renderViewPort(

at com.jme3.renderer.RenderManager.render(


at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(





I’ve you tried something like that :


final Nifty nifty = …;

application.enqueue( new Callable<Object>() {

public Object call() {


nifty.fromXml(“main.xml”, “mainLogin”);



I think all structural changes on Nifty screen should be done in the main loop.

In my case I have forfeit to use more than one screen.

I’ve transformed all my previous screen into custom control.

That way, when I want to switch screen, I juste have to hide, or remove the provious control from my screeen and add the new one.

The method Nifty.render() is not meant to be called directly…

I figured, but I couldn’t see any other remotely suitable functions to flush the screen/display for nifty.

I`ll try the method you have outlined didialchichi. :slight_smile: Thanks.

I tried as you had mentioned, but it still did not clear the screen o_0, I think at this stage hiding and showing layers (acting as if they were screens) will be the way I will go.

@Momoko_Fan Do we still need to use xml file for making GUI? wasn’t java supposed to be enough for doing the whole xml stuff after Nifty 1.3 implementation?


It’s right that we can now use JAVA to create the screens. But it doesn’t mean that the XML way became deprecated.

In my point of view, XML is still a good option :

People creating the assets and people creating the code can be different and I like the idea of having more than one possible display for a screen. ( depending of the prenferences of the user )

@shanec :

Well, I think its best not to paly with the creation of nifty displays.

Keeping only one screen, and managing its content via layers and panels is a wise decision, in my point of view.

If you still want tp have separate files for your “layers”, transform your current ‘screen’ into ‘controlDefinition’

iamcreasy said:
@Momoko_Fan Do we still need to use xml file for making GUI? wasn't java supposed to be enough for doing the whole xml stuff after Nifty 1.3 implementation?

You can create nifty guis by using the XML or by writing Java code. You can also choose not to use either and do it via jME3 gui node.

Guys, you think too much inside your code. The reason for css on the web is the same as using XML for the GUI. You can design it after the code has been written, without changing anything to the code. Even a designer could improve your UI. So you should lay out the basic blocks of you UI in XML and then modify this basis dynamically using code. Even if it seems easier to you while writing the code to just say “open window here” its not anymore when the game has really grown and the UI is modified/constructed from all ends of code… Thats where you will happily open your XML file to make the right bar just take 10% of the screen… Instead of modifying at least 10 lines of code. So yes, we do need the XML :stuck_out_tongue:

1 Like

I currently use a seperate XML for each screen and it works like a charm. All I do to switch to the new scrreen, in the new xml is this:

nifty.fromXml(CONFIGURATION_NIFTY_ROOT + dsMsg.getScreenName() + XML_EXT, dsMsg.getScreenName());

No call to Nifty.exit(), no call to Nifty.update(). just Nifty.fromXML() and everything works as it should.