
208
|
Chapter 5, Windows, Dialogs, and Frames
#40 Minimize to a Mini-Frame
HACK
I Shall Call Him...Mini-Me
Switching a frame between two sizes is quite easy: just call setSize( ) and
you’re done. Doing it well is a bit more difficult, however. When you mini-
mize the window, you also need to remove the window decorations, hide
the menu bar, and remove the components that shouldn’t be visible in the
mini-view. This is a bit trickier, not the least of which because you can’t turn
off the window decorations of a frame once it has been created. But I’m get-
ting ahead of myself. First, you need a sample application.
Let’s take a simple clock program. The normal window looks like
Figure 5-11. The goal is to provide a mini version that looks like Figure 5-12.
This program has a clock, a panel with more configuration options (repre-
sented here with just the label More configuration), a menu bar, and a pop-
up menu for later use. Example 5-9 creates the interface and puts the com-
ponents in the right places, but it doesn’t do anything with them yet.
Figure 5-11. A normal application window
Figure 5-12. A mini application window
Example 5-9. The beginning of a clock with a mini version
public class MiniMizeHack implements MouseListener, ActionListener {
public JFrame frame;
public JPanel panel;
public JPopupMenu popup;