Drag and Drop JLabel
awt, drag-and-drop, java, swing
Solution
Change:
this.addMouseListener(new MouseAdapter(){
To:
this.addMouseMotionListener(new MouseAdapter(){
Problem
I have a bunch of JLables in a JPanel, and I am using a FlowLayout on the JPanel. Each label is 100% the width of the JPanel, so as I add labels to the JPanel the are vertically placed. What I would like to be able to do is click and drag a JLabel up or down in the list. Using this code, I was expecting "Here" to be printed to the output console, but it was not. What do I need to do for drag and drop? ``` public class LayerItem extends JLabel{ public LayerItem(){ this.addMouseListener(new MouseAdapter(){ @Override public void mouseDragged(MouseEvent evt){ lblMouseDragged(evt); } }); } public void lblMouseDragged(MouseEvent evt){ System.out.println("Here"); } } ```