Java Reference
In-Depth Information
public FontDialog(SketchFrame window) {
// Initialization as before...
// Button panel code as before...
// Set up the data input panel to hold all input components as before...
// Add the font choice prompt label as before...
// Set up font list choice component as before...
// Panel to display font sample as before...
//Create a split pane with font choice at the top
// and font display at the bottom
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL _ SPLIT,
true,
chooseFont,
display);
gbLayout.setConstraints(splitPane, constraints); // Split pane constraints
dataPane.add(splitPane); // Add to the data pane
// Plus the code for the rest of the constructor...
}
The constructor does it all. The first argument specifies that the pane supports two components, one
above the other. You can probably guess that for side-by-side components you would specify
JSplitPane.HORIZONTAL _ SPLIT . If the second constructor argument is true , the components are
redrawn continuously as the divider is dragged. If it is false the components are not redrawn until you
stop dragging the divider.
The third argument is the component to go at the top, or to the left for HORIZONTAL _ SPLIT , and the
fourth argument is the component to go at the bottom, or to the right, as the case may be.
We don't need to do it here, but you can change the components in a split pane. You have methods
setLeftComponent() , setRightComponent() , setTopComponent() , and
setBottomComponent() to do this. You just pass a reference to a component to whichever
method you want to use. There are also corresponding get methods to retrieve the components in a
split pane. You can even change the orientation by calling the setOrientation() method and
passing JSplitPane.HORIZONTAL _ SPLIT , or JSplitPane.VERTICAL _ SPLIT to it.
There is a facility to provide a widget on the divider to collapse and restore either pane. We don't need
it, but if you want to try this here, you can add a statement after the JSplitPane constructor call:
splitPane.setOneTouchExpandable(true);
Passing false to this method will remove the widget.
Once we have created the splitPane object we add it to the dataPane panel with constraints that
make it fill the full width of the container.
Next we can add the font size selection mechanism.
Search WWH ::




Custom Search