Java Reference
In-Depth Information
for toolbar buttons and menu items are available. This outline version of StatusBar has two fields of type
StatusPane that are the panes showing the current color and element type.
The StatusPane objects will be left-justified when they are added to the status bar, as a result of the
first argument to the setLayout() method call in the StatusBar constructor. The layout manager leaves a
10-pixel horizontal gap between successive panes in the status bar and a 3-pixel vertical gap between rows
of components. The border for the status bar is a single dark gray line that you add using the static cre-
ateLineBorder() method in the BorderFactory class.
The panes in the status bar need to display only a small amount of text, so you derive the StatusPane
class from the JLabel class; a pane for the status bar is a specialized kind of JLabel . The StatusBar con-
structor updates the information to be displayed in each pane initially by calling the setColorPane() and
setTypePane() methods. This ensures that the StatusPane objects display the default color and element
type that you defined for the application at startup. One or other of these methods is called whenever it is ne-
cessary to update the status bar. You will complete the definitions for setColorPane() and setTypePane()
when you've defined the detail of the StatusPane class.
The StatusPane class that is nested in StatusBar is derived from JPanel . A JPanel object can display
text, or an icon, or both. You can provision for status bar panes in Sketcher that display text, or text with an
icon. You need two constructors to accommodate this. Here's the inner class definition:
class StatusPane extends JLabel {
// Constructor - text only
public StatusPane(String text) {
super(text, LEFT);
setupPane();
}
// Constructor - text with an icon
public StatusPane(String text, Icon icon) {
super(text, icon, LEFT);
setupPane();
}
// Helper method for use by constructors
private void setupPane() {
setBackground(Color.LIGHT_GRAY);
// Set background color
setForeground(Color.BLACK);
// Set foreground color
setFont(paneFont);
// Set the fixed font
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.LOWERED), // Outside border
BorderFactory.createEmptyBorder(0,5,0,3)));
// Inside border
setPreferredSize(new Dimension(80,20));
}
private Font paneFont =
new Font("Serif", Font.PLAIN, 10); // Font for pane text
}
Search WWH ::




Custom Search