Java Swing GUI

How to Change the Size of a JFrame(window) in Java

In this tutorial, we are going to see how to change the size of a jframe(window) in Java. To resize a frame, JFrame provides a method JFrame.setSize(int width, int height), it needs two parameters “width” and “height”. Here is what the code looks like now:
 

Java Program to Change the Size of a JFrame:
import javax.swing.JFrame;

public class Main 
{  
  public static void main(String[] args)
  {
	   JFrame frame = new JFrame();
	   frame.setSize(300, 300);    
	   frame.setVisible(true);
  }
}

Output:


[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *