Drad and drop in JPanel
I have a background image that is placed inside a JPanel. I would like to draw some objects over the background and to be able to drag and drop them. Currently I was able to achieve this effect by predefining the paint method of the JPanel. When I start dragging I check if the current mouse position is over an object and if so I redraw the object to the new coordinates and then draw the whole background again.
Is there a better way to do this? For example can I drag a JLabel with an icon and transparent background inside a JPanel? In general what would be the best technique to have this done?
Yes you can drag a JLabel easily over a JPanel doing what I think you want to do. JLayeredPane is useful in helping you do this.