
188
|
Chapter 5, Windows, Dialogs, and Frames
#36 Add Status Bars to Windows
HACK
adding the status bar to your frame with a BorderLayout or similar layout
that will stretch this component to the width of the window:
public JStatusBar( ){
setPreferredSize(new Dimension(getWidth( ), 23));
}
Painting Panel Details
Figure 5-7 shows the Windows Explorer status bar zoomed in around the
42.3 MB label. There are a couple of gray lines at the top and bottom, as
well as a blue line at the bottom, used to achieve a subtle gradation effect.
You can achieve this effect easily by overriding
paintComponent( ) and draw-
ing the lines yourself. Here is the overridden
paintComponent( ) code:
public void paintComponent(Graphics g) {
super.paintComponent(g);
int y = 0;
g.setColor(new Color(156, 154, 140));
g.drawLine(0, y, getWidth( ), y);
y++;
g.setColor(new Color(196, 194, 183));
g.drawLine(0, y, getWidth( ), y);
y++;
g.setColor(new Color(218, 215, 201));
g.drawLine(0, y, getWidth( ), y);
y++;
g.setColor(new Color(233, 231, 217));
g.drawLine(0, y, getWidth( ), y);
y = getHeight( ) - 3;
g.setColor(new Color(233, 232, 218));
g.drawLine(0, y, getWidth( ), y);
y++;
g.setColor(new Color(233, 231, 216));
g.drawLine(0, y, getWidth( ), y);
y = getHeight( ) - 1;
g.setColor(new Color(221, 221, 220));
g.drawLine(0, y, getWidth( ), y);
}
Figure 5-7. Explorer’s status bar zoomed in