Java Reference
In-Depth Information
public FontDialog(SketcherFrame 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
JPanel display = new JPanel(true);
fontDisplay = new JLabel("Sample Size: x X y Y z Z");
fontDisplay.setFont(font);
fontDisplay.setPreferredSize(new Dimension(350,100));
display.add(fontDisplay);
// Plus the code for the rest of the constructor...
}
Directory "Sketcher 5 displaying a font dialog"
You create the JPanel object display and add the JLabel object fontDisplay to it. The JPanel con-
structor with a true argument makes it double-buffered. This ensures flicker-free updating at the expense of
using more memory. Remember, you update this object in the valueChanged() handler for selections from
the list of font names. You also update it when the font size or style is changed. The fontDisplay object
just presents some sample text in the chosen font. You can choose different sample text if you like, but make
sure the preferred size is large enough to accommodate it at the maximum point size.
It's not strictly necessary here, but just for the experience you use a split pane to hold the scroll pane
containing the list, chooseFont , and the display panel.
Using a Split Pane
A JSplitPane object represents a pane with a movable horizontal or vertical split, so that it can hold two
components. The split pane divider can be adjusted by dragging it with the mouse. Here's the code to do
that:
public FontDialog(SketcherFrame 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...
Search WWH ::




Custom Search