Simplest draging of any JPanel

Hi all,

I've been reading all the tutorials on dragging and dropping, but they're all very specific -- how to drag text, how to drag images etc.

I'd like to be able to drag any JPanel (or, I assume, a class that extends JPanel) into another. The dragged JPanel would simply disappear from it's origin and be dropped into the target.

It seems like this should be an easy thing to do, but I'm feeling dumb -- I can't see any simple way of doing it!

Any help would be very, very much appreciated. I'm tearing my hair out!

[556 byte] By [TimQuinna] at [2007-11-27 11:05:58]
# 1

Look into the following interfaces ... DragGestureListener, DragSourceListener, Mouse Listener and ActionListener.

I use them in combination to get the results I want with a subclass of JPanel on an application that provides a toolbox of widgets (JPanel extenders) that can be dragged around the workspace and linked together in different ways.

PS.

puckstopper31a at 2007-7-29 13:12:12 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hmmm, I'm trying that but it doesn't appear to be helping.

This is my code for the JPanel. It doesn't yet have any dragging or dropping code. As you can see I'd like it to print out when I start dragging, but nothing happens when I click and drag.

public class DragSourceJPanel extends JPanel implements DragGestureListener, DragSourceListener{

public DragSourceJPanel(){

setSize(50,50);

setPreferredSize(new Dimension(50,50));

}

public void dragGestureRecognized(DragGestureEvent arg0) {

System.out.println("dragging");

}

public void dragDropEnd(DragSourceDropEvent arg0) {

System.out.println("dragging");

}

public void dragEnter(DragSourceDragEvent arg0) {

System.out.println("dragging");

}

public void dragExit(DragSourceEvent arg0) {

System.out.println("dragging");

}

public void dragOver(DragSourceDragEvent arg0) {

System.out.println("dragging");

}

public void dropActionChanged(DragSourceDragEvent arg0) {

System.out.println("dragging");

}

}

TimQuinna at 2007-7-29 13:12:12 > top of Java-index,Desktop,Core GUI APIs...