Java Reference
In-Depth Information
Directory "Sketcher 5 displaying a font dialog"
The JSplitPane constructor does it all. The first argument specifies that the pane supports two com-
ponents, one above the other. You can probably guess that for side-by-side components you 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.
NOTE You don't need to do it here, but you can change the components in a split pane.
You have four methods to do this: setLeftComponent() and setRightComponent() for a
horizontal arrangement of the panes, and setTopComponent() and setBottomComponent()
for a vertical arrangement of the panes. You just pass a reference to the component you
want to set to whichever method you want to use. There are also corresponding get meth-
ods to retrieve the components in a split pane. You can even change the orientation by call-
ing the setOrientation() method and passing either 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. You don't need
it, but if you want to try this here, you can add the following statement after the JSplitPane constructor
Calling this method with the argument as false removes the widget.
After you have created the splitPane object, you add it to the dataPane panel with constraints that make
it fill the full width of the container.
Next you can add the font size selection mechanism.
Using a Spinner
You could use another list for this, but to broaden your horizons you use another Swing component, a
javax.swing.JSpinner object. A JSpinner object displays a sequence of numbers or objects, and the user
can select any one from the set. The spinner displays up and down arrows at the side of the spinner for step-
ping through the list. You can also use the keyboard up and down arrow keys for this.
The sequence of choices in a spinner is managed by a javax.swing.SpinnerModel object. There are
three concrete spinner model classes defined in the javax.swing package. The one you use depends on
what sort of items you are choosing from:
SpinnerNumberModel is a model for a sequence of numbers. Numbers are stored internally and
returned as type Number , which is the superclass of the classes that encapsulate the primitive nu-
Search WWH ::

Custom Search