... selected values in copyJList
42                  copyJList.setListData(
43                     colorJList.getSelectedValuesList().toArray(
44                    new String[0]));
45               }
46            }
47         );
48
49         add(copyJButton); // add copy button to JFrame
50
51         copyJList = new JList<String>(); // list to hold copied color names
52         copyJList.setVisibleRowCount(5); // show 5 rows
53         copyJList.setFixedCellWidth(100); // set width
54         copyJList.setFixedCellHeight(15); // set height
55         copyJList.setSelectionMode(
56            ListSelectionModel.SINGLE_INTERVAL_SELECTION);
57         add(new JScrollPane(copyJList)); // add list with scrollpane
58      }
59   }

Fig. 26.26 Testing MultipleSelectionFrame.

 1   // Fig. 26.26: MultipleSelectionTest.java
 2   // Testing MultipleSelectionFrame.
 3   import javax.swing.JFrame;
 4
 5   public class MultipleSelectionTest ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.