List of usage examples for javax.swing JFrame getMaximumSize
public Dimension getMaximumSize()
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); }