Drag and drop in container

how i put the method of drag drop in container
this is my code

   public class InventoryState extends BaseAppState {

        static Logger log = LoggerFactory.getLogger(InventoryState.class);

        private Container mainWindow;
        private TabbedPanel tabs;

        private final List<Action> sessionActions = new ArrayList<>();
        private Container sessionButtons;

        public InventoryState(boolean enabled) {
            setEnabled(enabled);
            //  sessionActions.add(new CallMethodAction("Options", this, "disconnect"));
            //  sessionActions.add(new CallMethodAction("Characters", this, "disconnect"));
            // sessionActions.add(new CallMethodAction("Logout", this, "disconnect"));
            //sessionActions.add(new CallMethodAction("Exit", this, "exitGame"));
            // sessionActions.add(new CallMethodAction("Cancel", this,"cancel"));
        }

        /**
         * Returns the tabbed panel used in the in-game menu. This lets other states
         * potentially add their own in-game menu tabs.
         *
         * @return
         */
        public TabbedPanel getTabs() {
            return tabs;
        }

        protected void disconnect() {
            log.info("disconnect()");
            getState(OptionPanelState.class).show("Disconnect?", "Really disconnect?",
                    new CallMethodAction("Yes",
                            getState(ConnectionState.class),
                            "disconnect"),
                    new EmptyAction("No"),
                    new EmptyAction("Cancel"));
        }

        protected void exitGame() {
            log.info("exitGame()");
            getState(OptionPanelState.class).show("Exit Game?", "Really exit the whole game?",
                    new CallMethodAction("Yes",
                            getApplication(),
                            "stop"),
                    new EmptyAction("No"),
                    new EmptyAction("Cancel"));
        }

        protected void Options() {

        }

        protected void Characters() {
            log.info("Characters()");
            getState(OptionPanelState.class).show("Change Character", "Really disconnect?",
                    new CallMethodAction("Yes",
                            getState(ConnectionState.class),
                            "disconnect"),
                    new EmptyAction("No"),
                    new EmptyAction("Cancel"));
        }

        public List<Action> getSessionActions() {
            return sessionActions;
        }

        public void toggleEnabled() {
            setEnabled(!isEnabled());
        }

        @Override
        protected void initialize(Application app) {
            mainWindow = new Container();

            //   tabs = mainWindow.addChild(new TabbedPanel());
            sessionButtons = mainWindow.addChild(new Container());
           mainWindow.setPreferredSize(new Vector3f(200, 320, 0));
            Label o = sessionButtons.addChild(new Label("Inventory", new ElementId("title")));
    o.setFontSize(12);

    // Button p= sessionButtons.addChild(new Button("X"),1);
            o.setTextHAlignment(HAlignment.Center);
            Label f = sessionButtons.addChild(new Label("Default Cube", new ElementId("title")));
            f.setTextHAlignment(HAlignment.Center);
           f.setFontSize(12);
            Container barra1 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            // sessionButtons.addChild(new Label("Default Cube",new ElementId("title")));
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            barra1.addChild(new Container());
            Container barra2 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            barra2.addChild(new Container());
            Container barra3 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            barra3.addChild(new Container());
            Label b = sessionButtons.addChild(new Label("Expanded Cube 1", new ElementId("title")));
            b.setTextHAlignment(HAlignment.Center);
           b.setFontSize(12);
            Container barra4 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            barra4.addChild(new Container());
            Container barra5 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            barra5.addChild(new Container());
            Container barra6 = sessionButtons.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra6.addChild(new Container());
            barra1.setPreferredSize(new Vector3f(50, 25, 0));
            barra2.setPreferredSize(new Vector3f(50, 25, 0));
            barra3.setPreferredSize(new Vector3f(50, 25, 0));
            barra4.setPreferredSize(new Vector3f(50, 25, 0));
            barra5.setPreferredSize(new Vector3f(50, 25, 0));
            barra6.setPreferredSize(new Vector3f(50, 25, 0));
            
            /*  for (Action a : getSessionActions()) {
                sessionButtons.addChild(new ActionButton(a));
            }
             */
            // Calculate a standard scale and position from the app's camera
            // height
            int height = app.getCamera().getHeight();
            Vector3f pref = mainWindow.getPreferredSize().clone();

            float standardScale = getState(MainMenuState.class).getStandardScale();
            pref.multLocal(1.5f * standardScale);

            // With a slight bias toward the top        
            float y = height * 0.6f + pref.y * 0.0f;

            mainWindow.setLocalTranslation(250 * standardScale, y, 0);
            //  mainWindow.setLocalScale(1.5f * standardScale);

            InputMapper inputMapper = GuiGlobals.getInstance().getInputMapper();
            inputMapper.addDelegate(MainGameFunctions.F_IN_GAME_INVENTORY, this, "toggleEnabled");
        }

        @Override
        protected void cleanup(Application app) {

            InputMapper inputMapper = GuiGlobals.getInstance().getInputMapper();
            inputMapper.removeDelegate(MainGameFunctions.F_IN_GAME_INVENTORY, this, "toggleEnabled");
        }

        @Override
        protected void onEnable() {
            Node gui = ((Main) getApplication()).getGuiNode();
            gui.attachChild(mainWindow);
        }

        @Override
        protected void onDisable() {
            mainWindow.removeFromParent();
        }
    }

That’s kind of a big question.

Did you look at the drag and drop examples?

I see you adding a ton of empty containers… that seems really odd. You might want to use a GridPanel I guess for laying out your inventory.

yes i see the drag and drop example
and i can´t make it work
can you make a simple example

The drag and drop example is the simple example. And it works.

my problem i can´t adpte this code to work in my invetory class

package mygame;

/**
 *
 * @author Pedro Quesado
 */
import java.util.*;



import com.jme3.app.Application;

import com.jme3.app.state.BaseAppState;

import com.jme3.input.event.*;

import com.jme3.light.*;

import com.jme3.material.*;

import com.jme3.material.RenderState.BlendMode;

import com.jme3.material.RenderState.FaceCullMode;

import com.jme3.math.*;

import com.jme3.renderer.RenderManager;

import com.jme3.renderer.ViewPort;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.scene.*;

import com.jme3.scene.Spatial.CullHint;

import com.jme3.scene.control.AbstractControl;

import com.jme3.scene.debug.WireBox;

import com.jme3.scene.shape.*;



import com.simsilica.lemur.*;

import com.simsilica.lemur.dnd.*;

import com.simsilica.lemur.core.GuiMaterial;

import com.simsilica.lemur.event.*;



/**

 *  Demo and test of the drag-and-drop support in Lemur.

 *

 *  @author    Paul Speed

 */

public class Skills extends BaseAppState {



    private Node dndRoot;



    private ColorRGBA containerColor = new ColorRGBA(1, 1, 0, 0.5f);

    private ColorRGBA containerHighlight = new ColorRGBA(0, 1, 0, 0.5f);



    private ContainerNode container1;    

    private ContainerNode container2;



    public Skills() {

    }

    

    protected Node getRoot() {

        return dndRoot;

    }



    @Override 

    protected void initialize( Application app ) {

        dndRoot = new Node("dndRoot");

 

        DirectionalLight sun = new DirectionalLight(new Vector3f(1, -2, -5).normalizeLocal(),

                                                    ColorRGBA.White);

        dndRoot.addLight(sun);

        

        AmbientLight ambient = new AmbientLight(ColorRGBA.Gray);

        dndRoot.addLight(ambient);            

 

        // Setup a stack-based container       

        container1 = new ContainerNode("container1", containerColor);

        container1.setLocalTranslation(-3, 0, -4); 

        

        container1.addControl(new DragAndDropControl(new StackContainerListener(container1)));

        container1.addControl(new StackControl());        

        MouseEventControl.addListenersToSpatial(container1, 

                                                new HighlightListener(container1.material, 

                                                                      containerHighlight, 

                                                                      containerColor));

        dndRoot.attachChild(container1);

 

        // Setup a grid based container       

        container2 = new ContainerNode("container2", containerColor);

        container2.setSize(3, 3, 1);

        container2.setLocalTranslation(2f, -0.5f, -4);

        MouseEventControl.addListenersToSpatial(container2, 

                                                new HighlightListener(container2.material, 

                                                                      containerHighlight, 

                                                                      containerColor));

        container2.addControl(new GridControl(3));

        container2.addControl(new DragAndDropControl(new GridContainerListener(container2)));

        dndRoot.attachChild(container2);

        

        // Add some random items to our MVC stack 'model' control

        container1.getControl(StackControl.class).addChild(createItem());

        container1.getControl(StackControl.class).addChild(createItem());

        container1.getControl(StackControl.class).addChild(createItem());

        

        // Add some random items to our MVC grid 'model' control

        container2.getControl(GridControl.class).setCell(0, 0, createItem());  

        container2.getControl(GridControl.class).setCell(2, 1, createItem());  

    }

 

    private Spatial createItem() {

        Sphere sphere = new Sphere(12, 24, 1);

        Geometry geom = new Geometry("item", sphere);

        

        // Create a random color

        float r = (float)(Math.random() * 0.4 + 0.2);

        float g = (float)(Math.random() * 0.6 + 0.2);

        float b = (float)(Math.random() * 0.6 + 0.2);

        ColorRGBA color = new ColorRGBA(r, g, b, 1);

        

        Material mat = GuiGlobals.getInstance().createMaterial(color, true).getMaterial();

        //mat.getAdditionalRenderState().setWireframe(true);

        mat.setColor("Ambient", color);

        geom.setMaterial(mat);

        return geom;

    }

    

    @Override 

    protected void cleanup( Application app ) {

    }

    

    @Override

    protected void onEnable() {        

        ((Main)getApplication()).getRootNode().attachChild(dndRoot);

    }

    

    @Override

    protected void onDisable() {

        dndRoot.removeFromParent();

    }

    

    @Override

    public void update( float tpf ) {

        //System.out.println("-------- update -----");

    }

 

    /**

     *  Just to encapsulate the visuals needed to have both a wireframe

     *  view but an actual box for picking.

     */   

    private class ContainerNode extends Node {

 

        private GuiMaterial material;

        private WireBox wire;

        private Geometry wireGeom;

        private Box box;

        private Geometry boxGeom;

        

        public ContainerNode( String name, ColorRGBA color ) {

            super(name);

            material = GuiGlobals.getInstance().createMaterial(containerColor, false);

                   

            wire = new WireBox(1, 1, 1);

            wireGeom = new Geometry(name + ".wire", wire);

            wireGeom.setMaterial(material.getMaterial());

            attachChild(wireGeom);

            

            box = new Box(1, 1, 1);

            boxGeom = new Geometry(name + ".box", box);

            boxGeom.setMaterial(material.getMaterial()); // might as well reuse it

            boxGeom.setCullHint(CullHint.Always); // invisible

            attachChild(boxGeom);

        }

        

        private void setSize( float x, float y, float z ) {

            wire.updatePositions(x, y, z);

            box.updateGeometry(Vector3f.ZERO, x, y, z);

            box.clearCollisionData();

            

            wireGeom.updateModelBound();

            boxGeom.updateModelBound();

        }

    }

    

    private class StackControl extends AbstractControl {

    

        private ContainerNode node;

        private List<Spatial> model = new ArrayList<>();

 

        public StackControl() {

        }

 

        @Override       

        public void setSpatial( Spatial s ) {

            super.setSpatial(s);

            this.node = (ContainerNode)s;

            updateLayout();

        }

    

        public void addChild( Spatial child ) {

            model.add(child);

            node.attachChild(child);

            updateLayout();

        }



        public void addChild( int slot, Spatial child ) {

            model.add(slot, child);

            node.attachChild(child);

            updateLayout();

        }

        

        public void removeChild( Spatial child ) {

            model.remove(child);

            if( child.getParent() == node ) {

                node.detachChild(child);

            }            

            updateLayout();

        }



        public Spatial removeChild( int index ) {

            Spatial result = model.remove(index);

            updateLayout();

            return result;

        }

 

        protected void updateLayout() {

            int count = Math.max(1, model.size());

            node.setSize(1, count, 1);

            float yStart = -(count - 1);

            for( Spatial s : model ) {

                s.setLocalTranslation(0, yStart, 0);

                yStart += 2;

            }   

        }

    

        @Override

        protected void controlUpdate( float tpf ) {

        }

    

        @Override

        protected void controlRender( RenderManager rm, ViewPort vp ) {

        }

    }



    private class GridControl extends AbstractControl {

 

        private ContainerNode node;

        private int gridSize;

        private Spatial[][] grid;

    

        public GridControl( int gridSize ) {

            this.gridSize = gridSize;

            this.grid = new Spatial[gridSize][gridSize];

        }

    

        @Override       

        public void setSpatial( Spatial s ) {

            super.setSpatial(s);

            this.node = (ContainerNode)s;

            updateLayout();

        }

        

        public Spatial getCell( int x, int y ) {

            return grid[x][y];

        }

        

        public void setCell( int x, int y, Spatial child ) {

            if( grid[x][y] != null ) {

                grid[x][y].removeFromParent();

            }

            grid[x][y] = child;

            if( child != null ) {

                node.attachChild(child);

            }

            updateLayout();

        }

 

        public Spatial removeCell( int x, int y ) {

            Spatial result = grid[x][y];

            grid[x][y] = null;

            if( result != null ) {

                updateLayout();

            }

            return result;

        }

        

        public void addChild( Spatial child ) {

            // Find the first valid cell

            for( int x = 0; x < gridSize; x++ ) {

                for( int y = 0; y < gridSize; y++ ) {

                    // just in case the child is already in the grid 

                    if( grid[x][y] == child ) {

                        return; 

                    }

                    if( grid[x][y] == null ) {

                        setCell(x, y, child);

                        return;

                    }

                }

            }            

        }

        

        public void removeChild( Spatial child ) {

            for( int x = 0; x < gridSize; x++ ) {

                for( int y = 0; y < gridSize; y++ ) {

                    if( child == grid[x][y] ) {

                        if( child.getParent() == node ) {

                            child.removeFromParent();

                        }

                        grid[x][y] = null;

                    }

                }

            }

            updateLayout();

        }



        protected void updateLayout() {

            node.setSize(gridSize, gridSize, 1);

            for( int x = 0; x < gridSize; x++ ) {

                for( int y = 0; y < gridSize; y++ ) {

                    Spatial child = grid[x][y];

                    if( child != null ) {

                        child.setLocalTranslation(-(gridSize - 1) + x * 2, (gridSize - 1) - y * 2, 0);

                    }

                }

            }

        }    

        

        @Override

        protected void controlUpdate( float tpf ) {

        }

    

        @Override

        protected void controlRender( RenderManager rm, ViewPort vp ) {

        }

    }

    

    /**

     *  Listens for enter/exit events and changes the color of

     *  the geometry accordingly.

     */   

    private class HighlightListener extends DefaultMouseListener {

        private GuiMaterial material;

        private ColorRGBA enterColor;

        private ColorRGBA exitColor;

        

        public HighlightListener( GuiMaterial material, ColorRGBA enterColor, ColorRGBA exitColor ) {

            this.material = material;

            this.enterColor = enterColor;

            this.exitColor = exitColor;

        }

        

        public void mouseEntered( MouseMotionEvent event, Spatial target, Spatial capture ) {

            material.setColor(enterColor);

        }



        public void mouseExited( MouseMotionEvent event, Spatial target, Spatial capture ) {

            material.setColor(exitColor);

        }        

    }



    private class StackContainerListener implements DragAndDropListener {    



        private Spatial container;



        public StackContainerListener( Spatial container ) {

            this.container = container;            

        }



        /**

         *  Returns the container 'model' (in the MVC sense) for this

         *  container listener.

         */

        public StackControl getModel() {

            return container.getControl(StackControl.class); 

        }



        private int getIndex( Vector3f world ) {

            Vector3f local = container.worldToLocal(world, null);

            

            // Calculate the index for that location

            float y = (getModel().model.size() + local.y) / 2;

            

            return (int)y;

        }

        

        public Draggable onDragDetected( DragEvent event ) {

        

            System.out.println("Stack.onDragDetected(" + event + ")");

 

            // Find the child we collided with

            StackControl control = getModel();

            

            // For now just use the first one

            if( control.model.isEmpty() ) {

                return null;

            }

            

            int index = getIndex(event.getCollision().getContactPoint());

 

            // The item is being dragged out of the container so remove it.

            Spatial item = control.removeChild(index);

            

            // Note: the item is still a child to the container so that we

            // can get its world translation and such below.  One of the slightly

            // strange things about using Spatials instead of some game object

            // as our container items.

            

            // We'll trust that the drag session won't lose it if we need

            // to put it back.                       

            event.getSession().set(DragSession.ITEM, item);

            

            // We'll keep track of the slot we took it from so we can stick

            // it back again if the drag is canceled. 

            event.getSession().set("stackIndex", index);

 

            // Clone the dragged item to use in our draggable and stick the

            // clone in the root at the same world location.

            Spatial drag = item.clone();

            drag.setLocalTranslation(item.getWorldTranslation());

            drag.setLocalRotation(item.getWorldRotation());

            getRoot().attachChild(drag);

                   

            // Now that we've got the world location of the item we can remove

            // it from the parent spatial since it is not really a child anymore.

            // We only left it so we could easily get its world location/rotation.

            item.removeFromParent();

             

            return new ColoredDraggable(event.getViewPort(), drag, event.getLocation());

        } 

    

        public void onDragEnter( DragEvent event ) {

            System.out.println("++++++++ Stack.onDragEnter(" + event + ")");

        }

          

        public void onDragExit( DragEvent event ) {

            System.out.println("-------- Stack.onDragExit(" + event + ")");

        }

        

        public void onDragOver( DragEvent event ) {

            System.out.println("Stack.onDragOver(" + event + ")");

            

            // Any location is valid on the stack

            event.getSession().setDragStatus(DragStatus.ValidTarget);

        }  

    

        // Target specific

        public void onDrop( DragEvent event ) {

            System.out.println("Stack.onDrop(" + event + ")");

 

            // Grab the payload we stored during drag start

            Spatial draggedItem = event.getSession().get(DragSession.ITEM, null);

 

            // Add the item to this stack

            getModel().addChild(draggedItem);

        }

    

        // Source specific  

        public void onDragDone( DragEvent event ) {

            System.out.println("Stack.onDragDone(" + event + ")");            

            

            // Check to see if drop target was null as this indicates

            // that the drag operation didn't finish and we need to 

            // put the item back.           

            if( event.getSession().getDropTarget() == null ) {

                                           

                // Grab the payload we stored during drag start

                Spatial draggedItem = event.getSession().get(DragSession.ITEM, null);

            

                // Grab the original slot of the item.  We tucked this away

                // during drag start just for this case.                

                int slot = event.getSession().get("stackIndex", 0);

                

                getModel().addChild(slot, draggedItem);

            } 

        }

    }  

    

    private class GridContainerListener implements DragAndDropListener {    



        private Spatial container;



        public GridContainerListener( Spatial container ) {

            this.container = container;            

        }



        /**

         *  Returns the container 'model' (in the MVC sense) for this

         *  container listener.

         */

        public GridControl getModel() {

            return container.getControl(GridControl.class); 

        }



        private Vector2f getCellLocation( Vector3f world ) {

            Vector3f local = container.worldToLocal(world, null);

            

            // Calculate the cell location

            float x = (3 + local.x) / 2;

            float y = (3 - local.y) / 2;

            

            // This will look a little off to the user towards the right edge because

            // clicking on the surface of the box in the center cell will actually project

            // into the sphere in the last column.  But it works for a demo.  We could

            // also have made a ray and done collideWith() on the childre but I wanted

            // to show model-cell interaction instead of picking.

            int xCell = (int)x;

            int yCell = (int)y; 

 

            return new Vector2f(xCell, yCell);

        }



        public Draggable onDragDetected( DragEvent event ) {

        

            System.out.println("Grid.onDragDetected(" + event + ")");

 

            // Find the child we collided with

            GridControl control = getModel();

 

            // See where we hit

            Vector2f hit = getCellLocation(event.getCollision().getContactPoint());

 

            // Remove the item from the grid if it exists.

            Spatial item = control.removeCell((int)hit.x, (int)hit.y);

            if( item != null ) {

                // Save the item in the session so the other containers (and ourselves)

                // know what we are dragging.

                event.getSession().set(DragSession.ITEM, item);

                

                // We'll keep track of the grid cell in case the drag is

                // canceled and we have to put it back. 

                event.getSession().set("gridLocation", hit);

                

                // Clone the dragged item to use in our draggable and stick the

                // clone in the root at the same world location.

                Spatial drag = item.clone();

                drag.setLocalTranslation(item.getWorldTranslation());

                drag.setLocalRotation(item.getWorldRotation());

                getRoot().attachChild(drag);

                

                // Now that we've got the world location of the item we can remove

                // it from the parent spatial since it is not really a child anymore.

                // We only left it so we could easily get its world location/rotation.

                item.removeFromParent(); 

                

                return new ColoredDraggable(event.getViewPort(), drag, event.getLocation());

            }       

            return null;

        } 

    

        public void onDragEnter( DragEvent event ) {

            System.out.println("+++++++ Grid.onDragEnter(" + event + ")");

        }

          

        public void onDragExit( DragEvent event ) {

            System.out.println("------- Grid.onDragExit(" + event + ")");

        }

        

        public void onDragOver( DragEvent event ) {

            System.out.println("Grid.onDragOver(" + event + ")");

            

            Vector2f hit = getCellLocation(event.getCollision().getContactPoint()); 

            Spatial item = getModel().getCell((int)hit.x, (int)hit.y);

            if( item == null ) {

                // An empty cell is a valid target

                event.getSession().setDragStatus(DragStatus.ValidTarget);

            } else {

                // A filled slot is not

                event.getSession().setDragStatus(DragStatus.InvalidTarget);

            }

        }  

    

        // Target specific

        public void onDrop( DragEvent event ) {

            System.out.println("Grid.onDrop(" + event + ")");

            

            Spatial draggedItem = event.getSession().get(DragSession.ITEM, null);                        



            Vector2f hit = getCellLocation(event.getCollision().getContactPoint());

            

            // One last check to see if the drop location is available 

            Spatial item = getModel().getCell((int)hit.x, (int)hit.y);

            if( item == null ) {

                // Then we can stick the new child right in

                getModel().setCell((int)hit.x, (int)hit.y, draggedItem);

            } else {

                // It wasn't really a valid drop

                event.getSession().setDragStatus(DragStatus.InvalidTarget);   

            }

        }

    

        // Source specific  

        public void onDragDone( DragEvent event ) {

            System.out.println("Grid.onDragDone(" + event + ")");

            

            DragSession session = event.getSession();

            

            // Check to see if drop target was null as this indicates

            // that the drag operation didn't finish and we need to 

            // put the item back.                       

            if( session.getDropTarget() == null ) {

            

                // Grab the payload we stored during drag start

                Spatial draggedItem = session.get(DragSession.ITEM, null);

                

                // Grab the original slot of the item.  We tucked this away

                // during drag start just for this case.                

                Vector2f slot = session.get("gridLocation", null);

                if( slot != null ) {

                    getModel().setCell((int)slot.x, (int)slot.y, draggedItem);

                } else {

                    System.out.println("Error, missing gridLocation for dragged item");

                    // This should not ever happen but if it does we'll at least

                    // try to deal with it

                    getModel().addChild(draggedItem);

                }  

            } 

        }

    }  

    

    private class ColoredDraggable extends DefaultDraggable {

 

        private Material originalMaterial;

        private ColorRGBA color = ColorRGBA.Blue; 

        private ColorRGBA none = ColorRGBA.Gray;

        private ColorRGBA invalid = ColorRGBA.Red;

        

        private Geometry geom;

        private Material mat;

    

        public ColoredDraggable( ViewPort view, Spatial spatial, Vector2f start ) {

            super(view, spatial, start);

 

            this.geom = (Geometry)spatial;

            this.originalMaterial = geom.getMaterial(); 

            this.mat = originalMaterial.clone();

        }

 

        protected void setColor( ColorRGBA color ) {

            mat.setColor("Diffuse", color);

            mat.setColor("Ambient", color);

            geom.setMaterial(mat);

        }

 

        @Override       

        public void updateDragStatus( DragStatus status ) {

            switch( status ) {

                case InvalidTarget:

                    setColor(invalid);

                    break;

                case ValidTarget:

                    //setColor(color);

                    geom.setMaterial(originalMaterial);

                    break;  

                case NoTarget:

                default:

                    setColor(none);                    

                    break;

            }

        }        

    }

}

The art of debugging is a cruel mistress…

I create a inventory system my problem i can´t put work my grab system
i grab some code of example of pickingdemo.java
how create a grab event to grab my container and move arond the map
i can move around but i don´t need press the mouse event

          protected void initialize(Application app) {
            mainWindow = new Container();

            // mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            Label o = mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            o.setFontSize(12);
            o.setPreferredSize(new Vector3f(50, 25, 0));
            o.setTextHAlignment(HAlignment.Center);
            Label f = mainWindow.addChild(new Label("Default Cube", new ElementId("title")));
            f.setTextHAlignment(HAlignment.Center);
            f.setFontSize(12);
            f.setPreferredSize(new Vector3f(50, 25, 0));
            Panel[][] data = new Panel[4][8];
            Panel[][] data1 = new Panel[4][8];
            Label slot1 = new Label("1");
            Label slot2 = new Label("2");
            Label slot3 = new Label("3");
            Label slot4 = new Label("4");
            Label slot5 = new Label("5");
            Label slot6 = new Label("6");
            Label slot7 = new Label("7");
            Label slot8 = new Label("8");
            Label slot9 = new Label("1");
            Label slot10 = new Label("2");
            Label slot11 = new Label("3");
            Label slot12 = new Label("4");
            Label slot13 = new Label("5");
            Label slot14 = new Label("6");
            Label slot15 = new Label("7");
            Label slot16 = new Label("8");
            Label slot17 = new Label("1");
            Label slot18 = new Label("2");
            Label slot19 = new Label("3");
            Label slot20 = new Label("4");
            Label slot21 = new Label("5");
            Label slot22 = new Label("6");
            Label slot23 = new Label("7");
            Label slot24 = new Label("8");
            Label slot25 = new Label("1");
            Label slot26 = new Label("2");
            Label slot27 = new Label("3");
            Label slot28 = new Label("4");
            Label slot29 = new Label("5");
            Label slot30 = new Label("6");
            Label slot31 = new Label("7");
            Label slot32 = new Label("8");
            Label slot33 = new Label("1");
            Label slot34 = new Label("2");
            Label slot35 = new Label("3");
            Label slot36 = new Label("4");
            Label slot37 = new Label("5");
            Label slot38 = new Label("6");
            Label slot39 = new Label("7");
            Label slot40 = new Label("8");
            Label slot41 = new Label("1");
            Label slot42 = new Label("2");
            Label slot43 = new Label("3");
            Label slot44 = new Label("4");
            Label slot45 = new Label("5");
            Label slot46 = new Label("6");
            Label slot47 = new Label("7");
            Label slot48 = new Label("8");
            Label slot49 = new Label("1");
            Label slot50 = new Label("2");
            Label slot51 = new Label("3");
            Label slot52 = new Label("4");
            Label slot53 = new Label("5");
            Label slot54 = new Label("6");
            Label slot55 = new Label("7");
            Label slot56 = new Label("8");
             Label slot57 = new Label("1");
            Label slot58 = new Label("2");
            Label slot59 = new Label("3");
            Label slot60 = new Label("4");
            Label slot61 = new Label("5");
            Label slot62 = new Label("6");
            Label slot63 = new Label("7");
            Label slot64 = new Label("8");
            
            slot2.setPreferredSize(new Vector3f(50, 25, 0));
            slot3.setPreferredSize(new Vector3f(50, 25, 0));
            slot4.setPreferredSize(new Vector3f(50, 25, 0));
            slot5.setPreferredSize(new Vector3f(50, 25, 0));
            slot6.setPreferredSize(new Vector3f(50, 25, 0));
            slot7.setPreferredSize(new Vector3f(50, 25, 0));
            slot8.setPreferredSize(new Vector3f(50, 25, 0));

            data[0][0] = slot1;
            data[0][1] = slot2;
            data[0][2] = slot3;
            data[0][3] = slot4;
            data[0][4] = slot5;
            data[0][5] = slot6;
            data[0][6] = slot7;
            data[0][7] = slot8;
            data[1][0] = slot9;
            data[1][1] = slot10;
            data[1][2] = slot11;
            data[1][3] = slot12;
            data[1][4] = slot13;
            data[1][5] = slot14;
            data[1][6] = slot15;
            data[1][7] = slot16;
            data[2][0] = slot17;
            data[2][1] = slot18;
            data[2][2] = slot19;
            data[2][3] = slot20;
            data[2][4] = slot21;
            data[2][5] = slot22;
            data[2][6] = slot23;
            data[2][7] = slot24;
            data[3][0] = slot25;
            data[3][1] = slot26;
            data[3][2] = slot27;
            data[3][3] = slot28;
            data[3][4] = slot29;
            data[3][5] = slot30;
            data[3][6] = slot31;
            data[3][7] = slot32;

            CustomGridPanel ola = new CustomGridPanel(new ArrayGridModel<>(data));
    ola.getModel().setCell(3, 7, data[3][7]);
    ola.setVisibleRows(4);

    ola.setVisibleColumns(8);
      ola.setInsets(new Insets3f(10, 10, 0, 10));
            System.err.println(""+ola.getModel().getColumnCount());
              System.err.println(""+ola.getModel().getRowCount());
    //ola.setPreferredSize(new Vector3f(400, 400, 0));

            mainWindow.addChild(ola);
            // ola.setPreferredSize(new Vector3f(25, 350, 0));

            mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            data1[0][0] = slot33;
            data1[0][1] = slot34;
            data1[0][2] = slot35;
            data1[0][3] = slot36;
            data1[0][4] = slot37;
            data1[0][5] = slot38;
            data1[0][6] = slot39;
            data1[0][7] = slot40;
            data1[1][0] = slot41;
            data1[1][1] = slot42;
            data1[1][2] = slot43;
            data1[1][3] = slot44;
            data1[1][4] = slot45;
            data1[1][5] = slot46;
            data1[1][6] = slot47;
            data1[1][7] = slot48;
            data1[2][0] = slot49;
            data1[2][1] = slot50;
            data1[2][2] = slot51;
            data1[2][3] = slot52;
            data1[2][4] = slot53;
            data1[2][5] = slot54;
            data1[2][6] = slot55;
            data1[2][7] = slot56;
            data1[3][0] = slot57;
            data1[3][1] = slot58;
            data1[3][2] = slot59;
            data1[3][3] = slot60;
            data1[3][4] = slot61;
            data1[3][5] = slot62;
            data1[3][6] = slot63;
            data1[3][7] = slot64;
            Container loginPanel=mainWindow.addChild(new Container());
           GridPanel maria = new GridPanel(new ArrayGridModel<>(data1));
            loginPanel.addChild(maria);
           maria.setVisibleRows(4);
    maria.setVisibleColumns(8);
            mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            mainWindow.addChild(new Label("Inventory", new ElementId("title")));
            mainWindow.addChild(new Label("Inventory", new ElementId("title")));

            mainWindow.setPreferredSize(new Vector3f(350, 450, 0));
            int height = app.getCamera().getHeight();
            Vector3f pref = mainWindow.getPreferredSize().clone();

            float standardScale = getState(MainMenuState.class).getStandardScale();
            pref.multLocal(1.5f * standardScale);

            // With a slight bias toward the top        
            float y = height * 0.9f + pref.y * 0.0f;

            mainWindow.setLocalTranslation(250 * standardScale, y, 0);

            InputMapper inputMapper = GuiGlobals.getInstance().getInputMapper();
            inputMapper.addDelegate(MainGameFunctions.F_IN_GAME_INVENTORY, this, "toggleEnabled");
     
            
            MouseEventControl.addListenersToSpatial(mainWindow,

                    new DefaultMouseListener() {

                        @Override

                      public void mouseButtonEvent(MouseButtonEvent event, Spatial target, Spatial capture) {


                         //   Material m = ((Geometry)target).getMaterial();

                         //   m.setColor("Color", ColorRGBA.Red);

                           if(event.getButtonIndex()==MouseInput.BUTTON_LEFT && event.isPressed()){
					event.setConsumed();
					System.out.println("Start drag");
			Vector3f wt = mainWindow.getWorldTranslation();
					mainWindow.setLocalTranslation(wt.x,wt.y,wt.z);
				}
				if(event.getButtonIndex()==MouseInput.BUTTON_LEFT && event.isReleased() && mainWindow != null){
					System.out.println("Stop drag");
//dragProxy.
				}
                   

                        }

                    

                        @Override
                        public void mouseEntered(MouseMotionEvent event, Spatial target, Spatial capture ) {

                            System.err.println("Passou o rato por cima");
                            //Material m = ((Geometry)target).getMaterial();

                          //  m.setColor("Color", ColorRGBA.Yellow);

                        }
                        



                        public void mouseExited( MouseMotionEvent event, Spatial target, Spatial capture ) {
 System.err.println("Mouse Saiu");
                           // Material m = ((Geometry)target).getMaterial();

                           // m.setColor("Color", ColorRGBA.Blue);

                        }                        
@Override
			public void mouseMoved(MouseMotionEvent event, Spatial target, Spatial capture) {
				System.out.println("move");
				//if(dragProxy != null){
					System.out.println(event.getDX());
					Vector3f wt = mainWindow.getWorldTranslation();
					mainWindow.setLocalTranslation(event.getX(),event.getY(),0);
					
					//check if above another ContainerView Spatial
					//check if fit in
					//check if satisfy filter
					//check if teleporter available
					
					
					event.setConsumed();
				//}
				super.mouseMoved(event, target, capture);
			}

                    });
        }