Java Reference
In-Depth Information
that the panel containing the list and the label containing the image to be dis-
played are side by side. The call to the
setOneTouchExpandable
method causes
the divider bar of the split pane to display the arrows that permit the user to
expand the panes one way or the other with one click of the mouse.
LISTING 11.14
//********************************************************************
// PickImage.java Author: Lewis/Loftus
//
// Demonstrates the use of a split pane and a list.
//********************************************************************
import
java.awt.*;
import
javax.swing.*;
public class
PickImage
{
//-----------------------------------------------------------------
// Creates and displays a frame containing a split pane. The
// user selects an image name from the list to be displayed.
//-----------------------------------------------------------------
public static void
main (String[] args)
{
JFrame frame =
new
JFrame ("Pick Image");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JLabel imageLabel =
new
JLabel();
JPanel imagePanel =
new
JPanel();
imagePanel.add (imageLabel);
imagePanel.setBackground (Color.white);
ListPanel imageList =
new
ListPanel (imageLabel);
JSplitPane sp =
new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
imageList, imagePanel);
sp.setOneTouchExpandable (
true
);
frame.getContentPane().add (sp);
frame.pack();
frame.setVisible(
true
);
}
}
Search WWH ::
Custom Search