How to maximize JFrame in Java Swing



To maximize JFrame in Java Swing, use the following −

JFrame.MAXIMIZED_BOTH

The following is an example to maximize JFrame in Java −

Example

package my;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SwingDemo extends JFrame {
   JPanel panel = new JPanel();
   public SwingDemo() {
      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setAlwaysOnTop(true);
      setResizable(true);
      setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
   }
   public static void main(String[] args) { new SwingDemo();
   }
}

The output is as follows. Here, the JFrame is visible with no border and title −

Output

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements