DnDConstants.ACTION_COPY
import java.awt.BorderLayout;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class Main extends JFrame implements DragGestureListener {
DragSource ds = new DragSource();
String[] items = { "Java", "C", "C++", "Lisp", "Perl", "Python" };
JList jl = new JList(items);
public Main() {
super("Gesture Test");
setSize(200, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);
DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(jl,
DnDConstants.ACTION_COPY, this);
setVisible(true);
}
public void dragGestureRecognized(DragGestureEvent dge) {
System.out.println("Drag Gesture Recognized!");
}
public static void main(String args[]) {
new Main();
}
}
Related examples in the same category