Java Swing Tutorials

Iconifying and Maximizing a frame in Java
previous Home Next

In this page of the program, we are going to learn about the Iconifying and maximizing a frame in java Swing. Iconifying means that the frame show in min form. By default the frame will be accept in the minimized form.

Code Description

frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG): It is the method of the JRootPane class which is used to set the window decoration type using the constant property PLAIN_DIALOG of the JRootPane class.

setExtendedState(): It is used to set the state of window to min and max. It uses the constant field of the JFrame class.

MAXIMIZED_BOTH: This state is used to maximize the frame horizontal and vertical.

ICONIFIED: This state checks whether the frame is minimized or not.

 

Example

package r4r;
import javax.swing.*;
public class iconifytest {
public static void main(String[] args){
JFrame frame = new JFrame("Iconifying and Maximizing to a Frame");
frame.setUndecorated(false);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);  //Maximizing the frame
frame.setExtendedState(JFrame.ICONIFIED | frame.getExtendedState());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
previous Home Next