/** Driver.java for image-list program. Our frame will consist * of a split pane. And in this pane, we'll have 2 panels: * a list-panel on the left listing the file names, and an * "image" panel on the right showing the image the user has * selected. * It takes a little finesse to get the image to appear exactly * how you want. For instance, in main() we specify the image * panel's size to be big enough to hold the largest picture. * And we set a border layout so that the image can be vertically * centered. (We could have used a box layout and put glue above * and below the image label.) To make the image horizontally * centered, we need to call setHorizontalAlignment() in the * JLabel (not JPanel) class. */ import java.awt.*; import javax.swing.*; public class Driver { public static void main(String [] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel imageLabel = new JLabel(); JPanel imagePanel = new JPanel(); imagePanel.setPreferredSize(new Dimension(700,500)); imagePanel.setLayout(new BorderLayout()); imagePanel.add(imageLabel, BorderLayout.CENTER); imageLabel.setHorizontalAlignment(SwingConstants.CENTER); ListPanel imageList = new ListPanel(imageLabel); JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, imageList, imagePanel); frame.getContentPane().add(pane); frame.pack(); frame.show(); } }