[SOLVED] Nifty - Right Click Element

Hi guys, another Problem with nifty:

PanelBuilder panelBuilder = new PanelBuilder("testElement");

Element element = panelBuilder.build(nifty, screen, panel);
element.getElementInteraction().getSecondary().setOnClickMethod(new NiftyMethodInvoker(nifty, "testmethod()", "argumentAsStr"));

Method in Controller Class:

public void testmethod(String arg)

When I rightclick, nothing happened. Funny things, when I do it via panelBuilder.interactOnClick("testmethod('test')");
it works. But interactOnClick is only Primary/Left-Click and I need Right-Click therefore I cant use it.

Please help …

You have the right method but I think you are using NiftyMethodInvoker wrong. I believe it should be…

new NiftyMethodInvoker(nifty, "testmethod('test')", controllerObject);

That is what I use in my code and it works fine. If that doesn’t work you may need to attach the nifty source and debug what is happening inside NiftyMethodInvoker. That’s what I always end up doing if it isn’t clear how to use nifty correctly.

1 Like

Thanks it works! I thought the controller reference is anyway solved through the panelBuilder.controller(…) method. The name is confusing ‘targetParam’. It is obvious that you think its the param for the Method which is called. Nevermind, I thank you again.

1 Like

To add to glh3586’s answer the controllerObject is the ScreenController (i.e. something which extends de.lessvoid.nifty.screen.ScreenController), the class that has the testMethod in it

1 Like