// Multiple-selection lists: Copying items from one List to another.
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

public class MultipleSelectionFrame extends JFrame 
{
   private JList toppingJList; // list to hold toppings
   private JList copyJList; // list to copy toppings into
   private JButton copyJButton; // button to copy selected toppings
   private final String toppingNames[] = { "chocolate syrup", "peanuts", "colored sprinkles", 
      "chocolate sprinkles", "pineapple syrup", "strawberries", "caramel", "pecans", "more ice cream", 
      "whipped cream", "gummi bears", "chocolate hard shell", "raisins" };

   // MultipleSelectionFrame constructor
   public MultipleSelectionFrame()
   {
      super( "Multiple Selection Lists - Favorite Ice Cream Toppings" );
      setLayout( new FlowLayout() ); // set frame layout

      toppingJList = new JList( toppingNames ); // holds all the toppings 
      toppingJList.setVisibleRowCount( 5 ); // show five rows
      toppingJList.setSelectionMode( 
         ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
		toppingJList.setToolTipText("Hold CONTROL key down to select multiple items");
      add( new JScrollPane( toppingJList ) ); // add list with scrollpane

      copyJButton = new JButton( "Favorites >>>" ); // create copy button
      copyJButton.addActionListener(

         new ActionListener() // anonymous inner class 
         {  
            // handle button event
            public void actionPerformed( ActionEvent event )
            {
               // place selected values in copyJList
               copyJList.setListData( toppingJList.getSelectedValues() );
            } // end method actionPerformed
         } // end anonymous inner class
      ); // end call to addActionListener

      add( copyJButton ); // add copy button to JFrame

      copyJList = new JList(); // create list to hold copied color names
      copyJList.setVisibleRowCount( 5 ); // show 5 rows
      copyJList.setFixedCellWidth( 150 ); // set width
      copyJList.setFixedCellHeight( 15 ); // set height
      copyJList.setSelectionMode( 
         ListSelectionModel.SINGLE_INTERVAL_SELECTION );
			copyJList.setToolTipText("Hold SHIFT key down to select contiguous items");
      add( new JScrollPane( copyJList ) ); // add list with scrollpane
   } // end MultipleSelectionFrame constructor
} // end class MultipleSelectionFrame