List of utility methods to do JFrame Center
void | centerFrame(Window owner) center Frame Dimension size = owner.getSize(); owner.setLocation(center(size, getViewableRectangle())); |
void | centerFrameOnMainDisplay(final JFrame frame) Center a frame on the main display final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] screens = ge.getScreenDevices(); if (screens.length < 1) { return; final Rectangle screenBounds = screens[0].getDefaultConfiguration().getBounds(); final int x = (int) ((screenBounds.getWidth() - frame.getWidth()) / 2); final int y = (int) ((screenBounds.getHeight() - frame.getHeight()) / 2); ... |
void | centerFrameOnScreen(JFrame frame) center Frame On Screen Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; ... |
void | centerFrameOnScreen(JFrame frame) Centers a JFrame on screen. final Dimension position = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2);
|
void | centerFrameTo(final JFrame frameToCenter, final Dimension orientDim) center Frame To Dimension frameSize = frameToCenter.getSize(); int x = (orientDim.width - frameSize.width) / 2; int y = (orientDim.height - frameSize.height) / 2; frameToCenter.setLocation(x, y); |
void | centerJFrame(JFrame frame) center J Frame int width = frame.getWidth(); int height = frame.getHeight(); Dimension screen = getScreenSize(); double x = ((double) screen.width / 2) - ((double) width / 2d); double y = ((double) screen.height / 2) - ((double) height / 2d); x = Math.round(x); y = Math.round(y); frame.setLocation((int) x, (int) y); ... |
void | centerOnFrame(JDialog dialog, JFrame frame) center On Frame Point frameLoc = frame.getLocation(); Dimension frameSize = frame.getSize(); Dimension dialogSize = dialog.getSize(); int dialogX = frameLoc.x + (frameSize.width - dialogSize.width) / 2; int dialogY = frameLoc.y + (frameSize.height - dialogSize.height) / 2; dialog.setLocation(dialogX, dialogY); |
void | centerOnFrame(JFrame frame, Component comp) center On Frame Point p = frame.getLocation(); int left = p.x + (frame.getWidth() - comp.getWidth()) / 2; int top = p.y + (frame.getHeight() - comp.getHeight()) / 2; comp.setLocation(left, top); |
void | centerOnParent(JDialog child, JFrame parent) Centers a Dialog on its parent frame; int posX = parent.getX() + (parent.getWidth() / 2) - (child.getWidth() / 2); int posY = parent.getY() + (parent.getHeight() / 2) - (child.getHeight() / 2); child.setBounds(posX, posY, child.getWidth(), child.getHeight()); |
void | centerOnScreen(JFrame frame, int screenID) Centers a frame on screen. Rectangle screenBounds = getScreenBounds(screenID); int x = screenBounds.x + screenBounds.width / 2 - frame.getWidth() / 2; int y = screenBounds.y + screenBounds.height / 2 - frame.getHeight() / 2; frame.setLocation(x, y); |