The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Frames  [11 examples]

e564. Iconifying and Maximizing a Frame

This example implements methods to iconify, deiconify, minimize, and maximize a frame. In general, you should not make calls such as Frame.setExtendedState(Frame.ICONIFIED) because this would destroy the maximized state of the frame. Instead, the Frame.ICONIFIED state should be combined with the current maximized state of the frame.
    // This method iconifies a frame; the maximized bits are not affected.
    public void iconify(Frame frame) {
        int state = frame.getExtendedState();
    
        // Set the iconified bit
        state |= Frame.ICONIFIED;
    
        // Iconify the frame
        frame.setExtendedState(state);
    }
    
    // This method deiconifies a frame; the maximized bits are not affected.
    public void deiconify(Frame frame) {
        int state = frame.getExtendedState();
    
        // Clear the iconified bit
        state &= ~Frame.ICONIFIED;
    
        // Deiconify the frame
        frame.setExtendedState(state);
    }
    
    // This method minimizes a frame; the iconified bit is not affected
    public void minimize(Frame frame) {
        int state = frame.getExtendedState();
    
        // Clear the maximized bits
        state &= ~Frame.MAXIMIZED_BOTH;
    
        // Maximize the frame
        frame.setExtendedState(state);
    }
    
    // This method minimizes a frame; the iconified bit is not affected
    public void maximize(Frame frame) {
        int state = frame.getExtendedState();
    
        // Set the maximized bits
        state |= Frame.MAXIMIZED_BOTH;
    
        // Maximize the frame
        frame.setExtendedState(state);
    }

 Related Examples
e559. Creating a Frame
e560. Setting the Icon for a Frame
e561. Making a Frame Non-Resizable
e562. Removing the Title Bar of a Frame
e563. Setting the Bounds for a Maximized Frame
e565. Hiding a Frame When Its Close Button Is Clicked
e566. Exiting an Application When a Frame Is Closed
e567. Getting All Created Frames in an Application
e568. Determining When a Frame or Window Is Opened or Closed
e569. Determining When a Frame or Window Is Iconized or Maximized

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    GridBagLayout    Images    Shapes    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.