Learning Java Chapter 14: Using Swing Components
The JSplitPane Class
A split pane is a special container that holds two components, each
in its own sub-pane. A splitter bar adjusts the sizes of the two
sub-panes. In a document viewer, you could use a split pane to show a table
of contents next to a full document.
The following example capitalizes on the ImageComponent class
from the previous example. It displays two ImageComponents,
wrapped in JScrollPanes, in either side of a
JSplitPane. You can drag the splitter bar back and forth to
adjust the sizes of the two contained components.
//file: SplitPaneFrame.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class SplitPaneFrame {
public static void main(String[] args) {
String fileOne = "Piazza di Spagna.jpg";
String fileTwo = "L1-Light.jpg";
if (args.length > 0) fileOne = args[0];
if (args.length > 1) fileTwo = args[1];
// create a JFrame to hold everything
JFrame f = new JFrame("SplitPaneFrame");
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }
});
f.setSize(300, 200);
f.setLocation(200, 200);
Image leftImage = Toolkit.getDefaultToolkit( ).getImage(fileOne);
Component left =
new JScrollPane(new ImageComponent(leftImage));
Image rightImage = Toolkit.getDefaultToolkit( ).getImage(fileTwo);
Component right =
new JScrollPane(new ImageComponent(rightImage));
JSplitPane split =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
split.setDividerLocation(100);
f.getContentPane( ).add(split);
f.setVisible(true);
}
}
This example is shown in Figure 14-7.
Figure 14-7. Using a split pane
|
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|