Nifty GUI Button doesn't respond on Mouse Click

I’m new at jme3 and at first I wanted to make a kart game like Mario Kart so I started with a simple GUI to learn about AppStates and so on.

I followed the Instructions from the jme3 Nifty Gui

But if i click the button the startGame() method of the screencontroller isn’t triggered.

Here’s the XML code:

[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=“titleScreen” controller=“kartGame.TitleScreenState”>

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

<image filename=“Interface/start-background.png”></image>


<layer id=“foreground” backgroundColor="#0000" childLayout=“vertical” visibleToMouse=“true”>

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

<text text=“My Cool Kart Game” font=“Interface/Fonts/Default.fnt” width=“100%” height=“100%” />


<panel id=“panel_mid” height=“25%” width=“75%” align=“center” childLayout=“center”>

<text text=“This Game is still under Developing and this Screen is just for testing. Development Stadium is still far away from pre-alpha so: Use on your on own risk!”

font=“Interface/Fonts/Default.fnt” width=“100%” height=“100%” wrap=“true” />


<panel id=“panel_bottom_1” height=“15%” width=“75%” valign=“center” childLayout=“center” visibleToMouse=“true”>

<control name=“button” label=“Start” id=“StartButton” align=“center” valign=“center”

visibleToMouse=“true” >

<interact onClick=“startGame()”/>



<panel id=“panel_bottom_2” height=“15%” width=“75%” valign=“center” childLayout=“center” visibleToMouse=“true”>

<control name=“button” label=“Quit” id=“QuitButton” align=“center” valign=“center”

visibleToMouse=“true” >

<interact onClick=“quitGame()”/>






And here’s the TitleScreenStateClass wich implements the ScreenController.

[java]public class TitleScreenState extends AbstractAppState implements ScreenController {

private final ColorRGBA backgroundColor = ColorRGBA.Gray;

private Nifty nifty;

private Screen screen;

private KartGame game;

private NiftyJmeDisplay niftyDisplay;

public TitleScreenState(KartGame game){ = game;



public void initialize(AppStateManager stateManager, Application app) {

super.initialize(stateManager, app);

niftyDisplay = new NiftyJmeDisplay(game.getAssetManager(),




nifty = niftyDisplay.getNifty();

nifty.fromXml(“Interface/TitleScreen.xml”, “titleScreen”);




public void update(float tpf) {

/** any main loop action happens here */



public void stateAttached(AppStateManager stateManager) {




public void stateDetached(AppStateManager stateManager) {





public void bind(Nifty nifty, Screen screen) {

this.nifty = nifty;

this.screen = screen;


public void onStartScreen() {


public void onEndScreen() {


public void startGame(){


throw new RuntimeException(“Works”);

// I put an exception here that i defenitely note if the method is called or not



How do you instantiate TitleScreenState?

My thread might have some interesting information for you - read through it.

That’s an easy one to fix…

Since you don’t provide an instance of the ScreenController in your fromXML() call, Nifty tries to instantiate it via the default constructor. Since you don’t have a default constructor in your ScreenController, this will not be possibe, so the ScreenController will not be instantiated. As a result, there is no way for nifty to call your startGame() method on the ScreenController.

Adding a default controller should fix this. Or, if you want to put in the the current instance, you could pass it as a parameter to the fromXML() method.