List of utility methods to do Screen Center
void | setLocationCentral(final Component component) set Location Central final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension frameDimension = component.getSize(); final int x = (screenDimension.width - frameDimension.width) / 2; final int y = (screenDimension.height - frameDimension.height) / 2; component.setLocation(x, y); |
void | setLocationOnScreenToCenteredWithin(java.awt.Window window, java.awt.Component root) set Location On Screen To Centered Within java.awt.Dimension sizeDialog = window.getSize(); java.awt.Rectangle boundsRoot; if ((root != null) && root.isShowing()) { java.awt.Point locationRoot = root.getLocationOnScreen(); java.awt.Dimension sizeRoot = root.getSize(); boundsRoot = new java.awt.Rectangle(locationRoot, sizeRoot); } else { boundsRoot = window.getGraphicsConfiguration().getBounds(); ... |
void | setLocationToCenter(Window window) Sets the given Window to the center of the sceen window.setLocationRelativeTo(null); |
void | setSizeAndCenterOnSreen(Window window, double widthFactor, double heightFactor) Sets the size of the window to a width and height factor of the screen size, and centers it on the screen. setSize(window, widthFactor, heightFactor); centerOnScreen(window); |
Dimension | setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage) Geeft de waarden imgBorderWidth, imgSizeX & imgSizeY welke door imageShow() gebruikt worden. Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int newWidth, newHeight; int resize = size - centerPos; double resizeFactor; int maxscreenSize = (int) (screen.getHeight() * maxSizePercentage) / 100; if (image.getWidth() >= image.getHeight()) { resizeFactor = (maxscreenSize - image.getWidth()) / centerPos; newWidth = (int) (image.getWidth() + resize * resizeFactor); ... |
void | setWindowToCenterOfScreen(Window frm) set Window To Center Of Screen Rectangle screenBounds = frm.getGraphicsConfiguration().getBounds(); int center_x = screenBounds.x + screenBounds.width / 2; int center_y = screenBounds.y + screenBounds.height / 2; frm.setLocation(center_x - frm.getWidth() / 2, center_y - frm.getHeight() / 2); |
void | setWindowToScreenCenter(Window window) Move the specified window to the center of the screen. int screenWidth = window.getToolkit().getScreenSize().width; int screenHeight = window.getToolkit().getScreenSize().height; window.setLocation(screenWidth / 2 - window.getSize().width / 2, screenHeight / 2 - window.getSize().height / 2); |