Dragging an object from one panel to another

Hi,

I’m trying to make a JFrame that consists of 2 JPanels. The left panel has a list of buttons the user can press, and the right panel is a canvas for drawing graphics. Let’s say one of the buttons on the left panel is “place a square” such that if I press the button, I should be able to then move my mouse over to the canvas panel, and the moment my mouse enters the canvas panel region, a pre-drawn square will follow my mouse around. I can then move my mouse and left-click to “drop” the square on the location of the panel I want.

I know there are mouse motion listeners available, but I was wondering if anyone had any tips, advice, or links to demos with source code that implements this functionality.

Thanks!
DAT

Look at custom cursors. i believe this is what you wan’t. (Java supports Drag andf Drop but that really doesnt sound like what you are trying to do and woudl be over-kill.)

Mabye in the drawing panel you’ve got a list of shapes. When you click the new button you’d create a temp shape, and move its position with the cursor using mouse motion listener. When the mouse button is presses to place the shape, add it to the shape list and stop moving its position.