How to maximize JFrame in Java Swing

Java 8Object Oriented ProgrammingProgramming

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

raja
Published on 08-May-2019 15:49:37
Advertisements