[Solved] NiftyGUI Changing DragNDrop Parameters with Java

I hope this is a simple question. I have a Draggable for which I do not want the default revert behavior (I want it to stay where I release it). I understand that to do this in XML, one would do the following:


<control name=“draggable” revert=“false”/>


How does one accomplish this using Java? For completeness, how do you affect the other Draggable-specific parameters (handle and drop)? Here’s what I have. Commented lines are what I’ve tried to do, but they don’t seem to work for me:

Element parent = m_screen.findElementByName(“testLayer”);

CreateDraggable cd = new CreateDraggable();





// cd.setEffectsAttribute(“revert”, “false”);

// cd.setInteractAttribute(“revert”, “false”);

// cd.set(“revert”, “false”);

cd.create(m_nifty, m_screen, parent);


That’s a missing feature of CreateDraggable which you can work-around using the general set() method:

[java]cd.set(“revert”, “false”) {[/java]


Ok, I see you’ve tried that already. I’m pretty sure this is the correct way to set the “revert” attribute tho. The parent element of the draggable is using an absolute layout?

Edit 2:

I’ve checked it and it is the correct way to change the revert attribute. The problem here is that the dragCancel() method inside of Nifty always resets the parent of the draggable back to it’s original parent element. So if you add the Draggable to some element with childLayout=“absolute” and you drag it around and then you cancel the drag and the element has revert=“false” it will stay at the last position. If you use revert=“true” it will be reverted back to it’s original position before the drag.

However, this will only work as long as you add it to an element with childLayout=“absolute”. If you add it to some other childLayout then Nifty still tries to keep the position but since other layouts don’t care about the position it will look as if you set revert to “false”. The element will be back at its original position.


Yup, turns out the parent layer was set to “vertical.” Changing to “absolute” did the trick. Thanks a bunch!

1 Like

Sorry valcaris, I tried to give you +1 and clicked -1 by accident. Can someone fix it?