Nifty GUI and modality

Does anyone know if there is a way to create a modal element in nifty?

when you mean something like a modal dialog window, then the answer is yes! :slight_smile:

nifty popups usually block interaction with elements beneath them. there is however not yet much documentation available about this specific feature. you can find a working example in the nifty-examples project. when you quit the nifty-examples there is a popup window that asks you if you really want to quit.

It works like this:


somewhere in your xml

<popup id=“popupExit” childLayout=“center” backgroundColor="#000a">

<panel style=“nifty-panel-red” childLayout=“center” padding=“18px,28px,40px,16px” width=“30%” height=“20%” align=“center” valign=“center”>





somewhere in java

public void exit() {


nifty.showPopup(screen, “popupExit”, null);


1 Like

That’s exactly what i mean! As much as i hate having to convert all my pretty swing elements, i have to say i like nifty better and better.

Hope to be able to dig into styles soon, too.

Thanks for the tip!

Sry for reviving this thread but i get this:


at de.lessvoid.nifty.loaderv2.types.XmlBaseType.(

at de.lessvoid.nifty.loaderv2.types.ElementType.(

at de.lessvoid.nifty.loaderv2.types.PopupType.(

at de.lessvoid.nifty.Nifty.createPopupFromType(

at de.lessvoid.nifty.Nifty.createAndAddPopup(

at de.lessvoid.nifty.Nifty.createPopup(


While i have the xml code in my xml, and the create/showPopup right behind adding the nifty to the processor.

seems like your xml is broken o_O can you call nifty.validateXml(filename) and see if that passes? maybe share your xml too.

ah and just in case you’ve missed it: Popup Layers are now explained in the Wiki

Sorry for digging up this old topic, but I have stumbled upon the same problem as wutklumpen. I have exactly the same error. My xml looks like this:

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

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


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

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

<screen id="start" controller="game.MainMenuController">

<popup id="popupInit" childLayout="center" backgroundColor="#0008">

<panel id="popup_panel" height="25%" width="25%" align="center" valign="center" childLayout="center">

<text text="Initializing…" width="100%" height="100%" />



<layer id="background" childLayout="center">

<image filename="Interface/menu_bg_normal.png"></image>


<layer id="foreground" backgroundColor="#000a" childLayout="vertical">

<panel id="panel_top" height="25%" width="75%" align="center" childLayout="center">

<image filename="Interface/monopoly_logo.png"></image>


<panel id="panel_mid" height="50%" width="75%" align="center" childLayout="center">


<panel id="panel_bottom" height="25%" width="75%" align="center" childLayout="horizontal">

<panel id="panel_bottom_left" height="50%" width="50%" valign="center" childLayout="center">

<control name="button" label="Start" id="StartButton" align="center" valign="center" visibleToMouse="true">

<interact onClick="startGame(hud)"/>



<panel id="panel_bottom_right" height="50%" width="50%" valign="center" childLayout="center">

<control name="button" label="Join" id="JoinButton" align="center" valign="center" visibleToMouse="true">

<interact onClick="joinGame(hud)"/>






<screen id="hud" controller="game.InGameController">

<layer id="background" childLayout="center" backgroundColor="#0000">


<layer id="foreground" childLayout="center">

<panel height="48px" width="48px" align="center" valign="center" childLayout="center">

<image filename="Interface/cursor_arrow.png" width="48px" height="48px"></image>





Also I have noticed that I get the same error if I use any random string as the id of the popup in:

[java]popup = nifty.createPopup("popupInit");[/java]

What could be the problem?

I’m having the same problem as wutklumpen and conkerns above.

I define my popup as follows:

[xml]<popup id=“group_member_context” childLayout=“absolute-inside” width=“100px”>

<interact onClick=“closePopup()” onSecondaryClick=“closePopup()” onTertiaryClick=“closePopup()”/>

<control id="#menu" name=“niftyMenu” />

</popup>[/xml] (which is almost copied from the wiki guide)

In my Java code I call the following methods:


My stacktrace is:

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


at de.lessvoid.nifty.loaderv2.types.XmlBaseType.<init>(

at de.lessvoid.nifty.loaderv2.types.ElementType.<init>(

at de.lessvoid.nifty.loaderv2.types.PopupType.<init>(

at de.lessvoid.nifty.Nifty.createPopupFromType(

at de.lessvoid.nifty.Nifty.createAndAddPopup(

at de.lessvoid.nifty.Nifty.createPopup([/java]

I tried registering the popup first (with nifty.registerPopup(PopupType type)), but that didn’t seem to help.

Has anyone found a reason for the error and a solution?

@void256 said:
seems like your xml is broken o_O can you call nifty.validateXml(filename) and see if that passes? maybe share your xml too.

Also, why absolute-inside? It's purpose is for drag'ndrop and this kind of thing i think. But it should not be the cause of your issue.

Well, no, it doesn’t validate, but that’s because of the xsd-file not being up to date (it says interact can’t have onSecondaryClick and onTertiaryClick and childLayout can’t be absolute-inside). The rest passes fine.

The reason I have absolute-inside in the code above (I have tried other layouts and wasn’t going to use that one anyway) is because it has that value in the JME3 wiki guide here:

Edit: I think I found the problem… I will update this thread to post the solution if it is as I think it is. Seems to be just another problem with the xsd.


Indeed, I found the problem!

The wiki guide doesn’t mention that you have to put the popup outside of any screen. I had it inside a layer (which was perfectly permissable by the xsd). This is likely the problem the above posters had as well.

Once I put it outside of any screen, it worked as expected.

I’ve edited the wiki page to reflect this important fact, but it would be great if the xsd would disallow the use of the popup element where it won’t work.

1 Like