Example usage for javax.swing JFrame getMaximumSize

List of usage examples for javax.swing JFrame getMaximumSize

Introduction

In this page you can find the example usage for javax.swing JFrame getMaximumSize.

Prototype

public Dimension getMaximumSize() 

Source Link

Document

Returns the maximum size of this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setMaximumSize(new Dimension(350, 250));
    frame.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent evt) {
            Dimension size = frame.getSize();
            Dimension max = frame.getMaximumSize();
            if (size.getWidth() > max.getWidth()) {
                frame.setSize((int) max.getWidth(), (int) size.getHeight());
            }/*  w  w  w. j av a 2  s.  c  o  m*/
            if (size.getHeight() > max.getHeight()) {
                frame.setSize((int) size.getWidth(), (int) max.getHeight());
            }
        }
    });
    frame.setSize(200, 100);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}