Here you can find the source of resize(JComponent component, Dimension size)
private static void resize(JComponent component, Dimension size)
//package com.java2s; /**//from w ww .ja va 2 s. c o m * Copyright (c) 2016, Lindsay Bradford and other Contributors. * All rights reserved. * * This program and the accompanying materials are made available * under the terms of the BSD 3-Clause licence which accompanies * this distribution, and is available at * http://opensource.org/licenses/BSD-3-Clause */ import java.awt.*; import javax.swing.*; public class Main { private static void resize(JComponent component, Dimension size) { component.setPreferredSize(size); component.setMaximumSize(size); component.setMinimumSize(size); } private static void setMaximumSize(Dimension maxComponentSize, JComponent component) { final Dimension componentSize = component.getPreferredSize(); maxComponentSize.width = Math.max(maxComponentSize.width, (int) componentSize.getWidth()); maxComponentSize.height = Math.max(maxComponentSize.height, (int) componentSize.getHeight()); } }