
Minimize to a Mini-Frame #40
Chapter 5, Windows, Dialogs, and Frames
|
211
HACK
on right-clicks. If you are using Java 5.0, you can add another line to make
the frame always be on top. This can be annoying to some users, however,
so a real program would have a preference to control that feature:
// hide the extra components
bottom.hide( );
// add the pop up
panel.addMouseListener(this);
// stay on top
frame.setAlwaysOnTop(true);
// show the frame again
frame.pack( );
frame.setLocation(location);
frame.setVisible(true);
With the frame prepared, the code packs it, gives it the location of the origi-
nal frame, and makes it visible again.
Restore the Frame
When the user triggers the pop-up menu and selects Normal, the
switchToNormal( ) method will be called. This method reverses what the
switchToMini( ) method did:
public void switchToNormal( ) {
// nuke the old frame and build a new one
Point location = frame.getLocation( );
frame.setVisible(false);
frame = new JFrame( );
frame.setUndecorated(false);
frame.getContentPane( ).add(panel);
// show the extra components
bottom.show( );
frame.setJMenuBar(menubar);
// hide the pop up
panel.removeMouseListener(this);
// turn off stay on top
frame.setAlwaysOnTop(false);
// show the frame again
frame.pack( );
frame.setSize(normal_size);
frame.setLocation(location);
frame.setVisible(true);
}