[Nifty1.3] subscription for mouse click event doesn't work

I add a panel using PanelBuilder.

If I use ‘interactOnClick’ (1), subcription for mouse click event also works. (2)

But when ‘interactOnClick’ is not called, subcription doesn’t work.

Is this a bug or what do I do wrong?


PanelBuilder builder = new PanelBuilder(panelId) {{

interactOnClick(String.format(“onClick(%s)”, panelId)); // <== (1)








layer.add(builder.build(nifty, screen, layer));

nifty.subscribe(screen, panelId, NiftyMousePrimaryClickedEvent.class, new EventTopicSubscriber<NiftyMousePrimaryClickedEvent>() { // <== (2)


public void onEvent(String topic, NiftyMousePrimaryClickedEvent data) {

Element element = screen.findElementByName(topic);

Vector3f v1 = VarPool.getVector3(element.getX(), screenHeight-element.getY(), 0);

Vector3f v2 = VarPool.getVector3(element.getX()+element.getWidth(), screenHeight-(element.getY()+element.getHeight()), 0);

dragBox.setCorner(v1, v2);






you mean when you omit the line (1) in your example then the event notification (2) does not work, right?

if that is what you mean, then I can explain it: when you use any of the interact tags in XML or the corresponding interact* call from Java then Nifty will automatically make the element visibleToMouse=“true”. By default all elements in Nifty are initialy invisible to the mouse and don’t generate any events. So in general to make elements respond to any mouse events you’ll need to set visibleToMouse to true (which is supported from java builders too).

Thank you! Now it works.

I’m slowly used to nifty. I like it. :slight_smile: