Java Swing Tutorial - Java JList.setDragEnabled(boolean b)








Syntax

JList.setDragEnabled(boolean b) has the following syntax.

public void setDragEnabled(boolean b)

Example

In the following code shows how to use JList.setDragEnabled(boolean b) method.

/*from w  ww  .  j  a v a2 s .  co  m*/
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

public class DragTest14 extends JFrame {

  JList jl;

  String[] items = { "Java", "C", "C++", "Lisp", "Perl", "Python" };

  public DragTest14() {
    super("Drag Test 1.4");
    setSize(200, 150);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    jl = new JList(items);
    jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jl.setDragEnabled(true);

    getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);
    setVisible(true);
  }

  public static void main(String args[]) {
    new DragTest14();
  }
}