JListPictureViewer

JListPictureViewer - pictureJList.setSelectionMode

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

View Full Document Right Arrow Icon
//Program to demonstrate JLIST / import java.awt.*; import javax.swing.*; import javax.swing.event.*; i public class JListPictureViewer extends JFrame implements ListSelectionListener { private String[] pictureNames = {"Pie Diagram", "Line Graph", "Bar Graph", "Table", "Normal Curve"}; private ImageIcon[] pictures = {new ImageIcon("pieDiagram.jpg"), new ImageIcon("lineGraph.jpg"), new ImageIcon("barGraph.jpg"), new ImageIcon("table.jpg"), new ImageIcon("normalCurve.jpg")}; private BorderLayout layoutBL; private JList pictureJList; private JScrollPane selectionJS; private JLabel promptJL; private JLabel displayPicJL; private JLabel infoJL; public JListPictureViewer() { super("Photo Viewer"); Container pane = getContentPane(); pane.setLayout(null); promptJL = new JLabel("Select an Image", SwingConstants.CENTER); promptJL.setSize(350, 20); promptJL.setLocation(10, 0); pane.add(promptJL); pictureJList = new JList(pictureNames); pictureJList.setVisibleRowCount(3);
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: pictureJList.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); pictureJList.addListSelectionListener(this); selectionJS = new JScrollPane(pictureJList); selectionJS.setSize(350, 60); selectionJS.setLocation(10, 20); pane.add(selectionJS); displayPicJL = new JLabel(pictures[4]); displayPicJL.setSize(350, 350); displayPicJL.setLocation(10, 50); pane.add(displayPicJL); infoJL = new JLabel(pictureNames[4], SwingConstants.CENTER); infoJL.setSize(350, 20); infoJL.setLocation(10, 380); pane.add(infoJL); setSize (380, 440); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String args) { JListPictureViewer picViewer = new JListPictureViewer(); } public void valueChanged(ListSelectionEvent e) { displayPicJL.setIcon( pictures[pictureJList.getSelectedIndex()]); infoJL.setText( pictureNames[pictureJList.getSelectedIndex()]); repaint(); } }...
View Full Document

Page1 / 2

JListPictureViewer - pictureJList.setSelectionMode

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