Nifty add a HoverEffect without XML

I’m trying to get an image made by an imagebuilder brighter when the mouse enters it.

public class GUI extends NiftyJmeDisplay{
	public GUI(AssetManager  assetManager,InputManager inputManager,AudioRenderer audioRenderer,ViewPort guiViewPort)
		Nifty gui = getNifty();		
		gui.addScreen("screen", new ScreenBuilder("screen"){{
	             controller(new DefaultScreenController());
	             layer(new LayerBuilder("foreground") {{
	                    image(new ImageBuilder("resume") {{
	                        controller(new DefaultScreenController());
			        onHoverEffect(new HoverEffectBuilder(""){{
	                        	//what goes here?

I removed all the unneeded parts of my code to make the sample clearer. I’d only be interested in answers that don’t use XML at all. The Nifty manual only explains this part with XML, which I do not want to use.

You would fill it in the same as any other effect. For example:

onHoverEffect(new HoverEffectBuilder("colorBar") {{
    effectParameter("color", "#444f");

In your case I would use the changeImage effect along with a sprite of your normal / hover / clicked button images and switch them with the image mode.

I see. Would one do it like this?

onHoverEffect(new HoverEffectBuilder("changeImage") {{
    effectParameter("image", "assets/img/menu/bar2.jpg");

This seems to give me a nullPointerException.

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
	at de.lessvoid.nifty.effects.impl.ChangeImage.deactivate(
	at de.lessvoid.nifty.effects.Effect.setActiveInternal(
	at de.lessvoid.nifty.effects.Effect.deactivate(
	at de.lessvoid.nifty.effects.EffectProcessorImpl.processHoverDeactivate(
	at de.lessvoid.nifty.effects.EffectManager.handleHoverDeactivate(
	at de.lessvoid.nifty.elements.Element.mouseEventHoverPreprocess(
	at de.lessvoid.nifty.screen.MouseOverHandler.processMouseEvent(
	at de.lessvoid.nifty.screen.Screen.forwardMouseEventToLayers(
	at de.lessvoid.nifty.screen.Screen.mouseEvent(
	at de.lessvoid.nifty.Nifty.forwardMouseEventToScreen(
	at de.lessvoid.nifty.Nifty.access$1600(
	at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(
	at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(
	at com.jme3.niftygui.InputSystemJme.onMouseMotionEventQueued(
	at com.jme3.niftygui.InputSystemJme.forwardEvents(
	at de.lessvoid.nifty.Nifty.update(
	at com.jme3.niftygui.InputSystemJme.endInput(
	at com.jme3.input.InputManager.processQueue(
	at com.jme3.input.InputManager.update(
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(
	at Source)

This is when you need to read the manual. The change image effect has an active and deactive image defined just like the xml. You have the right idea though.

Right. Figured it out, thanks. If anyone strolls by with the same problem, this is the code that works (where bar.jpg is the dark picture and bar2.jpg the highlighted one):

onHoverEffect(new HoverEffectBuilder("changeImage") {{
    effectParameter("active", "assets/img/menu/bar2.jpg");
    effectParameter("inactive", "assets/img/menu/bar.jpg");

And this will be of great help to you: