TestDND.javaAPI DocExample2571Tue Dec 12 18:59:34 GMT 2000None


public class TestDND extends Object
The tester class for the DNDList. This class creates the lists, positions them in a frame, populates the list with the default data.

Fields Summary
Constructors Summary
public TestDND()
constructor creates the frame, the lists in it and sets the data in the lists

    JFrame f = new JFrame("Drag and Drop Lists");
    DNDList sourceList = new DNDList();
    // add data to the source List
    DefaultListModel sourceModel = new DefaultListModel();
    sourceModel.addElement( "Source Item1");
    sourceModel.addElement( "Source Item2");
    sourceModel.addElement( "Source Item3");
    sourceModel.addElement( "Source Item4");
    // gets the panel with the List and a heading for the List
    JPanel sourcePanel = getListPanel(sourceList, "SourceList", sourceModel); 
    DNDList targetList = new DNDList();
    // add data to the target List 
    DefaultListModel targetModel = new DefaultListModel();
    targetModel.addElement( "Target Item1");
    targetModel.addElement( "Target Item2");
    targetModel.addElement( "Target Item3");
    targetModel.addElement( "Target Item4");
    JPanel targetPanel = getListPanel(targetList, "TargetList", targetModel); 
    JPanel mainPanel = new JPanel();
	mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
    mainPanel.add( sourcePanel );
    mainPanel.add( targetPanel );
    f.getContentPane().add( mainPanel );
    f.setSize (300, 300);
    f.addWindowListener (new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
    f.setVisible (true);
Methods Summary
private javax.swing.JPanelgetListPanel(DNDList list, java.lang.String labelName, javax.swing.DefaultListModel listModel)
a convenience method used for positioning of the ListBox and the Label.

list - the special DND List
labelName - the heading for the list
listModel - model for the list

        JPanel listPanel = new JPanel();
        JScrollPane scrollPane = new JScrollPane(list);
        JLabel nameListName = new JLabel(labelName );
        listPanel.setLayout( new BorderLayout());
        listPanel.add(nameListName, BorderLayout.NORTH);
        listPanel.add( scrollPane, BorderLayout.CENTER);
        return listPanel;     
public static voidmain(java.lang.String[] args)

    TestDND testDND = new TestDND();