Contoh Program Multiple Selection List di Java

COntoh program java berikut ini merupakan variasi dari contoh program list sebelumnya. Di dalam program ini, list dibuat agar bisa dipilih lebih dari satu pilihan.

Berikut ini tampilan programnya:
contoh-program-multiple-list-java

Berikut ini programnya:

01 import java.awt.*;
02 import java.awt.event.*;
03 import javax.swing.*;
04
05 public class MultipleSelectionTest extends JFrame {
06 private JList lstColor, lstCopy;
07 private JButton btnCopy;
08 private final String arrColorName[] =
09 { "Black","Blue","Cyan","Dark Gray","Gray","Green","Light Gray",
10 "Magenta","Orange","Pink","Red","Yellow","White"
11 };
12
13 public MultipleSelectionTest() {
14 super ("Multiple Selection List");
15
16 Container container = getContentPane();
17 container.setLayout(new FlowLayout());
18
19 lstColor = new JList (arrColorName);
20 lstColor.setVisibleRowCount(5);
21 lstColor.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
22 container.add(new JScrollPane (lstColor));
23
24 btnCopy = new JButton ("Copy >>>");
25
26 btnCopy.addActionListener(
27 new ActionListener() {
28 public void actionPerformed (ActionEvent e) {
29 lstCopy.setListData(lstColor.getSelectedValues());
30 }
31 } //end of class
32 );
33
34 container.add(btnCopy);
35
36 lstCopy = new JList();
37 lstCopy.setVisibleRowCount(5);
38 lstCopy.setFixedCellHeight(15);
39 lstCopy.setFixedCellWidth(100);
40 lstCopy.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
41 container.add(new JScrollPane(lstCopy))
42
43 setSize (400,300);
44 setLocationRelativeTo(null);
45 setVisible(true);
46 }
47
48 public static void main (String args[]) {
49 MultipleSelectionTest test = new MultipleSelectionTest();
50 test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
51 }
52
53 }

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: