Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
karthikeya Boyini

Use the setMinimumSize() method to set the minimum size limit for a JFrame −

JFrame frame = new JFrame();
frame.setMinimumSize(new Dimension(500, 300));

The following is an example to set minimum size limit for a JFrame −

Example

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
public class SwingDemo {
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      JButton button = new JButton("Close!");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setContentPane(button);
      button.addActionListener(e -> {
         frame.dispose();
      });
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setMinimumSize(new Dimension(500, 300));
      frame.getContentPane().setBackground(Color.ORANGE);
      frame.pack();
      frame.setVisible(true);
   }
}

Output

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.