Java Utililty Methods JDialog Center

List of utility methods to do JDialog Center

Description

The list of methods to do JDialog Center are organized into topic(s).

Method

voidcenter(JDialog dialog)
Center JDialog.
Dimension dialogSize = dialog.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation((screenSize.width - dialogSize.width) >> 1,
        (screenSize.height - dialogSize.height) >> 1);
voidcenter(JDialog 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));
voidcenterDialog(final JDialog target)
Centers JDialog on screen
final Rectangle screen = getScreenRect();
final Rectangle frameSize = target.getBounds();
final int x = (screen.width - frameSize.width) / 2;
final int y = (screen.height - frameSize.height) / 2;
target.setLocation(x, y);
voidcenterDialog(javax.swing.JDialog dialog)
Place a JDialog window to the center of computer screen.
java.awt.Dimension screenSize = dialog.getToolkit().getScreenSize();
java.awt.Dimension size = dialog.getSize();
screenSize.height = screenSize.height / 2;
screenSize.width = screenSize.width / 2;
size.height = size.height / 2;
size.width = size.width / 2;
int y = screenSize.height - size.height;
int x = screenSize.width - size.width;
...
voidcenterDialog(JDialog dDialog)
This method centers the given dialog.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = dDialog.getSize();
dDialog.setLocation((screenSize.width / 2) - (labelSize.width / 2),
        (screenSize.height / 2) - (labelSize.height / 2));
voidcenterDialog(JDialog dialog)
Centers the dialog on the screen.
dialog.setLocationRelativeTo(null);
voidcenterDialog(JDialog dialog)
Centers a JDialog to the screen.
final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
        .getDefaultConfiguration().getBounds();
final Dimension dialogSize = dialog.getSize();
if (dialogSize.height > screenSize.height) {
    dialogSize.height = screenSize.height;
if (dialogSize.width > screenSize.width) {
    dialogSize.width = screenSize.width;
...
voidcenterDialog(JDialog dialog, Container parent)
center Dialog
Dimension parentSize = parent.getSize();
Dimension dialogSize = dialog.getSize();
Point parentLocn = parent.getLocationOnScreen();
int locnX = parentLocn.x + (parentSize.width - dialogSize.width) / 2;
int locnY = parentLocn.y + (parentSize.height - dialogSize.height) / 2;
dialog.setLocation(locnX, locnY);
voidcenterDialogInContainer(JDialog dialog, Container frame)
center Dialog In Container
Dimension prefSize = dialog.getPreferredSize();
java.awt.Point parentLocation = frame.getLocationOnScreen();
Dimension parentSize = frame.getSize();
int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
dialog.setLocation(x, y);
voidcenterDialogInWindow(JDialog dialog, Window win)
center Dialog In Window
int posX = win.getLocation().x;
int posY = win.getLocation().y;
int dX = (win.getWidth() - dialog.getWidth()) / 2;
int dY = (win.getHeight() - dialog.getHeight()) / 2;
dialog.setLocation(posX + dX, posY + dY);