/* The program demonstrate the use of a list * */ import javax.swing.*; public class List extends JFrame { JPanel panel; JScrollPane scroll; JList list; JLabel msg; public List() { // Sets the title of the window setTitle("JList Window"); // Sets the size of the window setSize(300, 400); // Sets the action when the window close setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Sets the label of the window msg = new JLabel("Here are the months"); // Create a String of array String[] months = {"Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."}; // Adds the array of string into the list list = new JList(months); // Sets the visibility of the list list.setVisibleRowCount(5); // Adds the list to a scroll pane JScrollPane scroll = new JScrollPane(list); // Adds the scroll pane and the label to a panel panel = new JPanel(); panel.add(msg); panel.add(scroll); // Adds the panel to a content pane add(panel); // Set the window to be visible setVisible(true); } public static void main(String[] args) { new List(); } }