
Add Status Bars to Windows #36
Chapter 5, Windows, Dialogs, and Frames
|
189
HACK
The first section draws the gray lines at the top. Midway through, y is reset
based on the panel height, and then the bottom lines are drawn.
Add the Corner Icon
Next, you need to add the resize icon—preferably made to resemble real
Windows resize icons
[Hack #36]. Make a JLabel for the corner icon and add
the icon to it. Since this hack is mimicking the Explorer status bar, use the
TriangleSquareWindowsCornerIcon. Also, remember to set the label opacity to
false. This makes the status panel background show through the icon:
JLabel resizeIconLabel = new JLabel(new TriangleSquareWindowsCornerIcon( ));
resizeIconLabel.setOpaque(false);
Now, you need to add the label to the panel. You need the resize icon to be
at the right, on the bottom of the bar. For this to work, set the
JStatusBar
layout to a BorderLayout. Then create another panel called rightPanel and
set its
layout to BorderLayout as well. Add the rightPanel to the status bar,
to the east; add the resize icon to the
rightPanel, to the south. Don’t forget
to set the
rightPanel’s opacity to false as well. This will place the icon on
the bottom right of the status bar:
JPanel rightPanel = new JPanel(new BorderLayout( ));
rightPanel.setOpaque(false);
rightPanel.add(resizeIconLabel, BorderLayout.SOUTH);
add(rightPanel, BorderLayout.EAST);
While you’re at it, create another