Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Toolkit; import java.awt.Window; import javax.swing.SwingUtilities; public class Main { public static void pack(Component c) { Window window = getFrame(c); window.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension bounds = new Dimension(); bounds.width = Math.min(window.getWidth(), screenSize.width * 8 / 10); bounds.height = Math.min(window.getHeight(), screenSize.height * 8 / 10); window.setSize(bounds); } public static Frame getFrame(Component c) { Frame frame; if (c instanceof Frame) { frame = (Frame) c; } else { frame = (Frame) SwingUtilities.windowForComponent(c); } return frame; } }