Creating a Draggable inside a droppable

I’m creating a draggable with the following code:

[java]public void addItem() {
DraggableBuilder builder = new DraggableBuilder() {
{
width(“64px”);
height(“64px”);
childLayoutCenter();
valignTop();
text(new TextBuilder() {
{
font(“Interface/Fonts/Default.fnt”);
text(“Drag Me!”);
style(“descriptionText”);
}
});
}
};

    Element droppable = nifty.getCurrentScreen().findControl("slot01", DroppableControl.class).getElement();
    builder.build(nifty, nifty.getCurrentScreen(), droppable);
}[/java]

It creates a fully functional draggable, however it’s location is in the top left corner of screen, and the droppable is not in that same spot. How would I get it to be in correct position?

What does your Droppable code look like? It looks like you are creating the Draggable correctly. On a side note, is there a reason why you are finding your droppable element by the control instead of just looking for element directly?

I was finding the element by control to see if had any different effect than doing the normal “nifty.getCurrentScreen().findElementByName(“name”);”

Most of the inventory screen. It’s mostly repeats, creating 4 rows of inventory.

[java]<screen id=“inventory”>
<layer id=“inventory_container” childLayout=“center” width=“100%” height=“100%”>
<panel id=“container” height=“320px” width=“100%” align=“center” childLayout=“vertical”>
<panel id=“sack1” height=“20%” width=“640px” align=“center” childLayout=“horizontal”>
<control name=“droppable” id=“slot00” width=“64px” height=“64px” visibleToMouse=“true”>
<image id=“1” filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot01” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot02” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot03” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot04” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot05” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot06” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot07” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot08” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot09” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
</panel>
<panel id=“sack2” height=“20%” width=“640px” align=“center” childLayout=“horizontal”>
<control name=“droppable” id=“slot10” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot11” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot12” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot13” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot14” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot15” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot16” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot17” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot18” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
<control name=“droppable” id=“slot19” width=“64px” height=“64px” visibleToMouse=“true”>
<image filename=“Interface/empty.png”></image>
</control>
</panel>
[/java]

I just tried running your code real quick but added x(“0px”) and y(“0px”) to your draggable builder and it worked correctly. I have those same settings on my inventory from when I ran into this problem. I’m not entirely sure what causes it but I think it has something to do with the droppable control using absolute coordinates in one of its panels.

Well, that fixed it. Thanks glh3586