ListPanel - list.addListSelectionListener (new...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // ListPanel.java Authors: Lewis/Loftus // // Solution to Programming Project 9.5 // // Represents the list of images for the PickImage program. //******************************************************************** / import java.awt.*; import javax.swing.*; import javax.swing.event.*; i public class ListPanel extends JPanel { private JLabel label; private JList list; //----------------------------------------------------------------- // Loads the list of image names into the list. //----------------------------------------------------------------- public ListPanel (JLabel imageLabel) { label = imageLabel; String[] fileNames = { "cactus.jpg", "circuit.gif", "duckkey.jpg", "duke.gif", "hammock.gif", "justin.jpg", "kayak.jpg", "kayla.jpg", "tiger.jpg", "toucan.gif", "worldmap.gif" }; list = new JList (fileNames);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: list.addListSelectionListener (new ListListener()); list.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); add (scrollPane); setBackground (Color.white); } //***************************************************************** // Represents the listener for the list of images. //***************************************************************** private class ListListener implements ListSelectionListener { public void valueChanged (ListSelectionEvent event) { if (list.isSelectionEmpty()) label.setIcon (null); else { String fileName = (String)list.getSelectedValue(); ImageIcon image = new ImageIcon (fileName); label.setIcon (image); } } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

ListPanel - list.addListSelectionListener (new...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online