Here you can find the source of positionFrame(final JFrame frame, final Dimension viewSize, final int addX, final int addY)
Parameter | Description |
---|---|
frame | the frame to position. |
viewSize | the preferred size of the scrollable view. |
addX | the amount of width to add to the view. |
addY | the amount of height to add to the view. |
public static void positionFrame(final JFrame frame, final Dimension viewSize, final int addX, final int addY)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import java.awt.DisplayMode; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; public class Main { /**/*from w w w . j a va 2 s .c o m*/ * Set the size and location of the frame. * * @param frame the frame to position. * @param viewSize the preferred size of the scrollable view. * @param addX the amount of width to add to the view. * @param addY the amount of height to add to the view. */ public static void positionFrame(final JFrame frame, final Dimension viewSize, final int addX, final int addY) { final GraphicsDevice screenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice(); final DisplayMode displayMode = screenDevice.getDisplayMode(); final Dimension screenSize = new Dimension(displayMode.getWidth(), displayMode.getHeight()); final Dimension frameSize = new Dimension(Math.min(viewSize.width + addX, screenSize.width), Math.min(viewSize.height + addY, screenSize.height)); final int frameX = Math.max((screenSize.width - frameSize.width) / 2, 0); final int frameY = Math.max((screenSize.height - frameSize.height) / 2, 0); frame.setSize(frameSize); frame.setLocation(frameX, frameY); } }