O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required