List of utility methods to do JDialog Center
void | centerOn(JDialog dialog, Component other) center On int w = dialog.getWidth(); int h = dialog.getHeight(); Rectangle bounds = other.getBounds(); int bw = bounds.width; int bh = bounds.height; dialog.setLocation(bounds.x + (bw - w) / 2, bounds.y + (bh - h) / 2); |
void | centerOnComponent(JDialog dialog, Component comp) center On Component if (comp == null || !comp.isShowing()) { centerOnScreen(dialog); return; Rectangle b = comp.getBounds(); Point p = comp.getLocationOnScreen(); dialog.setLocation(p.x + (b.width - dialog.getWidth()) / 2, p.y + (b.height - dialog.getHeight()) / 2); |
void | centerOnScreen(JDialog jdialog) center On Screen int w = jdialog.getWidth(); int h = jdialog.getHeight(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); int bw = bounds.width; int bh = bounds.height; jdialog.setLocation((bw - w) / 2, (bh - h) / 2); |
void | centerWindow(JDialog dialog) center Window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); |
void | centerWindow(JDialog dialog) center Window Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int w = dialog.getSize().width; int h = dialog.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; dialog.setLocation(x, y); |
void | centrarVentana(JDialog pDialog) centrar Ventana Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension objectSize = pDialog.getSize(); if (objectSize.height > screenSize.height) { objectSize.height = screenSize.height; if (objectSize.width > screenSize.width) { objectSize.width = screenSize.width; pDialog.setLocation((((screenSize.width - objectSize.width) / 2)), (screenSize.height - objectSize.height) / 2); |
Point | getCentralDialogLocation(Component parent, JDialog dialog) get Central Dialog Location Point parentLocation = parent.getLocation(); Dimension parentSize = parent.getSize(); Dimension dialogSize = dialog.getSize(); int x = Math.max(0, parentLocation.x + parentSize.width / 2 - dialogSize.width / 2); int y = Math.max(0, parentLocation.y + parentSize.height / 2 - dialogSize.height / 2); return new Point(x, y); |
Rectangle | getCentredDialogBounds(JDialog dialog, Component parent, int defaultWidth, int defaultHeight) get Centred Dialog Bounds Dimension pref = dialog.getPreferredSize(); int w = pref.width; int h = pref.height; if (defaultWidth > 0) w = defaultWidth; if (defaultHeight > 0) h = defaultHeight; Rectangle parentBounds = parent.getBounds(); ... |
void | packAndCenterJDialog(JDialog form) pack And Center J Dialog form.pack(); form.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width) / 2 - form.getWidth() / 2, (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - form.getHeight() / 2); |
void | packInCenter(JDialog dialog) pack the dialog in the center of the screen dialog.pack(); Point center = getLocation(null); int x = center.x - dialog.getWidth() / 2; int y = center.y - dialog.getHeight() / 2; if (x < 20) { x = 20; if (y < 20) { ... |