List of utility methods to do JFrame Center
void | alignCenter(JInternalFrame internalFrame) align Center JDesktopPane desktopPane = internalFrame.getDesktopPane(); int desktopWidth = desktopPane.getWidth(); int desktopHeight = desktopPane.getHeight(); int frameWidth = internalFrame.getWidth(); int frameHeight = internalFrame.getHeight(); Point newLocation = new Point((desktopWidth - frameWidth) / 2, (desktopHeight - frameHeight) / 2); internalFrame.setLocation(newLocation); |
void | center(JFrame frame) Center JFrame. Dimension frameSize = frame.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1); |
void | center(JFrame frame) Description of the Method Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((int) ((screen_size.getWidth() - frame.getWidth()) / 2), (int) ((screen_size.getHeight() - frame.getHeight()) / 2)); |
void | center(JFrame parent, JInternalFrame dialog) Centers the supplied dialog in its parent's bounds. Dimension psize = parent.getSize(); Dimension dsize = dialog.getSize(); dialog.setLocation((psize.width - dsize.width) / 2, (psize.height - dsize.height) / 2); |
void | centerAndSizeFrame(JFrame frame) Centeres the frame on the user's screen and sets the size of it to a reasonable size. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int height = screenSize.height; int width = screenSize.width; frame.setSize(width / 2, height / 2); frame.setLocationRelativeTo(null); |
Dimension | centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight) Center a big window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int winWidth = screenSize.width - 40; int winHeight = screenSize.height - 150; if (winWidth > maxWidth) { winWidth = maxWidth; if (winHeight > maxHeight) { winHeight = maxHeight; ... |
void | centerDialog(final JFrame frame, JDialog dialog) Centers the dialog above the given frame int parWidth = frame.getWidth(); int parHeight = frame.getHeight(); int parX = frame.getLocation().x; int parY = frame.getLocation().y; Point loc = new Point(((parWidth - dialog.getWidth()) / 2) + parX, ((parHeight - dialog.getHeight()) / 2) + parY); dialog.setLocation(loc); |
void | centerDialog(JDialog dialog, JFrame frame) Centers a dialog in a frame if (dialog == null) { throw new NullPointerException("The dialog can't be null"); if (frame == null) { throw new NullPointerException("The frame can't be null"); final Dimension d = dialog.getSize(); dialog.setLocationRelativeTo(frame); ... |
void | centerDialog(JDialog dialog, JFrame parent) center Dialog Point p = parent.getLocationOnScreen(); p.x += ((parent.getWidth() - dialog.getWidth()) / 2); p.y += ((parent.getHeight() - dialog.getHeight()) / 2); if (p.y <= 0) p.y = 20; if (p.x <= 0) p.x = 20; dialog.setLocation(p); ... |
void | centerDialogIntoFrame(java.awt.Component p_CompToBePositioned, javax.swing.JFrame p_MainFrame) center Dialog Into Frame Dimension l_size = p_CompToBePositioned.getSize(); int y = p_MainFrame.getY() + ((p_MainFrame.getHeight() / 2) - (l_size.height / 2)); int x = p_MainFrame.getX() + ((p_MainFrame.getWidth() / 2) - (l_size.width / 2)); p_CompToBePositioned.setLocation(x, y); |