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:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MultipleSelectionTest extends JFrame {
	private JList lstColor, lstCopy;
	private JButton btnCopy;
	private final String arrColorName[] =
		{ "Black","Blue","Cyan","Dark Gray","Gray","Green","Light Gray",
		  "Magenta","Orange","Pink","Red","Yellow","White"
		};

	public MultipleSelectionTest() {
		super ("Multiple Selection List");		

		Container container = getContentPane();
		container.setLayout(new FlowLayout());

		lstColor = new JList (arrColorName);
		lstColor.setVisibleRowCount(5);
		lstColor.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		container.add(new JScrollPane (lstColor));

		btnCopy = new JButton ("Copy >>>");		

		btnCopy.addActionListener(
			new ActionListener() {
				public void actionPerformed (ActionEvent e) {
					lstCopy.setListData(lstColor.getSelectedValues());
				}
			} //end of class
		);

		container.add(btnCopy);		

		lstCopy = new JList();
		lstCopy.setVisibleRowCount(5);
		lstCopy.setFixedCellHeight(15);
		lstCopy.setFixedCellWidth(100);
		lstCopy.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		container.add(new JScrollPane(lstCopy))		

		setSize (400,300);
		setLocationRelativeTo(null);
		setVisible(true);
	}

	public static void main (String args[]) {
    	MultipleSelectionTest test = new MultipleSelectionTest();
    	test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}

Semoga bermanfaat dan maju terus ilmu pengetahuan Indonesia!

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading ... Loading ...
Java, Java Swing

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

6 Responses to “Contoh Program Multiple Selection List di Java”

Leave Comment

(required)

(required)


// Place This Code At The End Or After All Ad Zone Div Created