List of utility methods to do Screen Center
void | setCenter(Component comp) Center a component on the screen. Dimension screenSize = comp.getToolkit().getScreenSize(); Dimension frameSize = comp.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; comp.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); |
void | setCenter(Component comp, Component parent) Center a component within a parental component. if (parent == null) { setCenter(comp); return; Dimension dlgSize = comp.getPreferredSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if (dlgSize.width < frmSize.width && dlgSize.height < frmSize.height) ... |
void | setCenter(Component component) set Center Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); component.setLocation(screenSize.width / 2 - component.getWidth() / 2, screenSize.height / 2 - component.getHeight() / 2); |
void | setCenter(Component component, Component component1) set Center Point point; Dimension dimension; if (component != null) { point = component.getLocation(); dimension = component.getSize(); } else { dimension = Toolkit.getDefaultToolkit().getScreenSize(); point = new Point(0, 0); ... |
void | setCenteredCoordSystem(Graphics2D g, Component comp, double unitx, double unity) sets the coordinate system with given units and origin at the centre of the component in question. int dx = comp.getWidth(); int dy = comp.getHeight(); g.translate(dx / 2, dy / 2); g.scale(unitx, -unity); |
void | setCenteredInScreen(Component frame) set Centered In Screen setCenteredInScreen(frame, -1); |
Rectangle | setCenteredRectangle(int rectangleWidth, int rectangleHeight) set Centered Rectangle Dimension screenDimensions = Toolkit.getDefaultToolkit().getScreenSize(); int xCenter = (screenDimensions.width - rectangleWidth) / 2; int yCenter = (screenDimensions.height - rectangleHeight) / 2; return new Rectangle(xCenter, yCenter, rectangleWidth, rectangleHeight); |
void | setCenterLocation(final Window window) set Center Location final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation(dim.width / 2 - window.getSize().width / 2,
dim.height / 2 - window.getSize().height / 2);
|
void | setCenterPosition(final Frame frame) Set the position of the frame to the center of the screen final Dimension paneSize = frame.getSize(); final Dimension screenSize = frame.getToolkit().getScreenSize(); frame.setLocation((screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2); |
void | setComponentLocationOnCenter(Component component) Centers the specified component based on the user main screen dimensions and resolution. int screenID = getScreenID(component); Dimension dim = getScreenDimension(screenID); final int x = (dim.width - component.getWidth()) / 2; final int y = (dim.height - component.getHeight()) / 2; component.setLocation(x, y); |