Java tutorial
//package com.java2s; /* * @(#)SwingUtils.java * * Copyright 2010 MBARI * * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1 * (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.gnu.org/copyleft/lesser.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main { /** * <p><!-- Method description --></p> * * * @param frame */ public static void smartSetBounds(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = 500; int height = 500; if (screenSize.height <= 600) { height = (int) (screenSize.height * .95); } else if (screenSize.height <= 1000) { height = (int) (screenSize.height * .90); } else if (screenSize.height <= 1200) { height = (int) (screenSize.height * .85); } else { height = (int) (screenSize.height * .80); } if (screenSize.width <= 1000) { width = (int) (screenSize.width * .95); } else if (screenSize.width <= 1200) { width = (int) (screenSize.width * .90); } else if (screenSize.width <= 1600) { width = (int) (screenSize.width * .85); } else { width = (int) (screenSize.width * .80); } frame.setBounds(0, 0, width, height); } }