/*!Begin Snippet:file*/
import java.awt.*;
import javax.swing.*;

/**
 * Demonstrates the component {@link JList}. This class extends
 * class {@link @JPanel}.
 *
 * @author author name
 * @version 1.0.0
 */
public class JListDemo extends JPanel {

	private JList listOne;
	private JList listTwo;

	private static final String fruitNames[] =
			{"Orange", "Pear", "Apple", "Pineapple", "Peach",
			 "Grapefruit", "Lemon", "Grape"};

	/**
	 * Creates a window.
	 *
	 * @param args  not used.
	 */
	public static void main(String[] args) {

		JFrame frame = new JFrame("JListDemo");

		frame.setContentPane(new JListDemo());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();    // Adjust the size of the window
		frame.setVisible(true);
	}

	/**
	 * Creates two {@link JList} components.
	 */
	public JListDemo() {

		setBackground(Color.white);

		// Create the components
		listOne = new JList(fruitNames);
		listTwo = new JList(fruitNames);

		// Customize the list properties
		listOne.setVisibleRowCount(5);
		listTwo.setVisibleRowCount(5);
		listOne.setSelectionMode(
			ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		listTwo.setSelectionMode(
			ListSelectionModel.SINGLE_SELECTION);
		listOne.setFixedCellHeight(15);
		listOne.setFixedCellWidth(100);
		listTwo.setFixedCellHeight(15);
		listTwo.setFixedCellWidth(100);

		// Change the colors of the lists
		listOne.setBackground(new Color(0, 0, 150));
		listTwo.setBackground(new Color(0, 150, 0));
		listOne.setForeground(Color.white);
		listTwo.setForeground(Color.white);

		// Add lists to the scrollbar containers
		add(new JScrollPane(listOne,
			JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
			JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		add(new JScrollPane(listTwo,
			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
			JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
	}
}
/*!End Snippet:file*/

