Nifty Event Problems

Hi everyone. I’m trying to learn how to use Nifty (noob+Nifty!=good lol) and I seem to be having some problems with events. I can get a couple of the events to work (onStartScreen, onEndScreen, onActive) but I can’t seem to get any of the mouse-related events (onHover, onClick). Also, when I click on the panel it bleeds through to the canvas (when I click and drag on the panel it clicks and drags on the canvas). Is there a way to disable that? Here’s the code:

[java]package test;


import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.system.AppSettings;

import com.jme3.system.JmeCanvasContext;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import java.awt.Canvas;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;


import javax.swing.JFrame;

public class TestNiftyGui extends SimpleApplication implements ScreenController {

private Nifty nifty;

public static void main(String[] args){

JFrame frame = new JFrame(“Test”);







AppSettings settings = new AppSettings(true);



final TestNiftyGui app = new TestNiftyGui();





JmeCanvasContext context = (JmeCanvasContext) app.getContext();

Canvas canvas = context.getCanvas();

canvas.setSize(settings.getWidth(), settings.getHeight());

frame.addWindowListener(new WindowAdapter() {


public void windowClosing(WindowEvent e) {






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.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));



NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,inputManager,audioRenderer,guiViewPort);

nifty = niftyDisplay.getNifty();


nifty.fromXml(“test/xml/helloworld.xml”, “start”, this);

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


// disable the fly cam

// flyCam.setEnabled(false);



public void bind(Nifty nifty, Screen screen) {

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


public void onStartScreen() {



public void onEndScreen() {



public void quit(){



public void die(){


private Element getElement(final String id) {

return nifty.getCurrentScreen().findElementByName(id);





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

<nifty xmlns=“” xmlns:xsi=“” xsi:schemaLocation=“”>

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

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

<screen id=“start” controller=“de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen”>

<layer id=“layer” backgroundColor=”#23ffff00" childLayout=“center” width=“80%” height=“90%” >

<panel id=“panel” backgroundColor="#103f" childLayout=“vertical” padding=“15px,2px,22px,3px” width=“25%” height=“100%” align=“right”>

<text font=“verdana-small-regular.fnt” text=“MOOO” align=“center” valign=“top” />

<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>


<onClick name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>



<panel id=“panel3” backgroundColor="#112f" childLayout=“center” align=“left” valign=“top” padding=“20px,20px,20px,20px” width=“30%” height=“30%” visibletomouse=“true”>






Any ideas? Thanks.


For started, this is wrong.


<screen id="start" controller="de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen">


should be something like (make sure the path is right and points to the REAL screen controller):


<screen id="start" controller="test.TestNiftyGui">


Woops… Well, I guess that’s what happens when you just base a program off of another one… Thanks for fixing that :slight_smile: Now the events work with buttons and stuff (just tested it out… I was wondering why my methods weren’t getting called :wink: ). Unfortunately, it still doesn’t fix the non-control events… Darn :confused:

nomnom said:
Unfortunately, it still doesn't fix the non-control events.... Darn :/

What exactly isn't working? Details please (code too if necessary).

Ummmm, code is above (most of the time it is necessary :slight_smile: ).

I’ll try to explain this a bit better: I have a panel that I want to colorPulsate onHover (or click). It works when I do onActive, but not onClick or onHover.

What I want:

[xml]<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>


<onHover name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>



However, that doesn’t work.

What does work:

[xml]<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>


<onActive name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>



Does that make a bit more sense? Sorry for the confusion. Thanks!


Some effects in nifty are kinda broken or not entirely working depending on many factors. Just out of curiosity, could you please test the above with onStartHover?

Nop, didn’t work… It also said that I didn’t have it (I’m running Eclipse with the nightly from 2 days ago). Right now I’m downloading tonight’s nightly and then I’ll try it again. Thanks.


Alright, done some test and I can confirm that this is effing weird.

Seems to me the effect will only activate on an elemnet that is “full screen” or something like that… If I attach your effect to the main layer of the screen, it works fine, if I attach it to one of the children element I’m getting nothing.

@void256 ?

Yay! It wasn’t a completely noobish mistake! Thanks… Hopefully void can figure it out…


nomnom said:
Yay! It wasn't a completely noobish mistake! Thanks... Hopefully void can figure it out...


Not that one, yeah. But I wouldn't brag about noobish mistake after the ScreenController above. ;) lol j/k

Hehehe, yeah… But at least some one corrected me :wink: lol


Erm, maybe it’s simply that you need to write that one attribute correct:


instead of


You know, XML is case sensitive? :slight_smile:

Besides that issue this works quite well here. Actually it would make sense because Nifty won’t care about the “visibletomouse” property and therefore the mouse does not “see” the panel at all. That’s why it works with onActive because there is no mouse involved with that kind of effect ^^

Aw, crap… In the end it was a stupid mistake… Thanks void!