Here you can find the source of packAndCenter(Window wind)
Parameter | Description |
---|---|
wind | the windows to pack and center to the screen |
static public void packAndCenter(Window wind)
//package com.java2s; /*/*from ww w .j a v a2s.c o m*/ * GuiHelper.java * * Copyright (C) 2009 Nicola Roberto Vigan? * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { /** * Packs and centers the windows * @param wind the windows to pack and center to the screen */ static public void packAndCenter(Window wind) { wind.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = wind.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } wind.setSize(frameSize); wind.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } }