NiftyGui Populating Droppables in Java

I would like to be able to populate a Droppable in Java. For example, I want to do something like:

[java]DroppableControl drop = screen.findElementByName(“thedroppable”).getNiftyControl(DroppableControl.class);
Draggable drag = new Draggable();
drop.drop(drag);[/java]

However, DroppableControl.drop() is a private function. It seems the only way around this is to actually drag the Draggable and drop it on the Droppable:

[java]int x = drop.getElement().getX();
int y = drop.getElement().getY();
drag.drag(x, y);
drag.dragStop();[/java]

This isn’t working though. I think it’s because my mouse isn’t at [x,y]. Any thoughts/suggestions? I would like to avoid the extra overhead of actual dragging and dropping since I know which Droppable I want to drop into, so there’s no need to search for it at [x,y].

You can populate them just like any other nifty element. There is no need to call the drop command to add it. You add draggable element as a child to the droppable element using a builder. Look up the “Laying Out the GUI in Java” in the tutorials if you don’t know how to use the builders. When you call the build command one of the options is what parent element you want to add the element to. That’s the way I do it with my inventory control right now.

1 Like

I thought I was making it harder than it had to be. Thanks!!