Maximize a FrameTag(s): AWT


// place this in the Frame constructor, after the show()
this.move(0,0);
resize(Toolkit.GetDefaultToolkit().getScreenSize());
JDK1.2 offers a new method, setState(), to minimize or maximize a Frame.
frame.setState(Frame.ICONIFIED);  // minimize the frame
Latest JDK provides more ways to do that.

JDK1.4

import java.awt.*; 
...
GraphicsDevice device;
Frame frame = new Frame();
device = 
  GraphicsEnvironment.
      getLocalGraphicsEnvironment().
         getDefaultScreenDevice();
if ( device.isFullScreenSupported() ) { 
  device.setFullScreenWindow(frame);
}
else { 
  System.err.println("Full screen not supported"); 
}
The "full-screen" Frame is in exclusive mode. In this mode you can change the resolution
import java.awt.*;

class ScreenRes {
  public static void main(String args[]) {
      new ScreenRes().doit();
  }

  public void doit() {
    Frame frame = new Frame();
    GraphicsDevice device;
    device = 
      GraphicsEnvironment.
        getLocalGraphicsEnvironment().
           getDefaultScreenDevice();
    if ( device.isFullScreenSupported() ) {
      device.setFullScreenWindow(frame);
      if (device.isDisplayChangeSupported()) {
        device.setDisplayMode(
           new DisplayMode( 1024, 768,
                            8, // bitDepth - 8 bits 256 colors
                            DisplayMode.REFRESH_RATE_UNKNOWN ));

      }
      else {
            System.err.println("Change display mode not supported");
          }
    }
    else {
      System.err.println("Full screen not supported");
    }
  }
}
When the JFrame is destroyed, the original resolution is restored.

To remove (manually) the "exclusive mode" on the JFrame :

 
device.setFullScreenWindow(null);

SWING jdk1.3

JFrame frame = new JFrame();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
// can be
//  frame.setExtendedState(Frame.MAXIMIZED_HORIZ);
//  frame.setExtendedState(Frame.MAXIMIZED_VERT);

blog comments powered by Disqus