Example usage for javax.swing JFrame setLocation

List of usage examples for javax.swing JFrame setLocation

Introduction

In this page you can find the example usage for javax.swing JFrame setLocation.

Prototype

@Override
public void setLocation(int x, int y) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:Main.java

/**
 * Centers a {@link JFrame} on screen./*from  w ww .  j  a  va2 s.  c  o m*/
 */
public static void centerFrameOnScreen(JFrame frame) {
    final Dimension position = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2);
}

From source file:Main.java

/**
 * Position in center a JFrame/*w w w.  ja  v  a 2 s  .c  om*/
 *
 * @param jFrame
 */
public static void center(JFrame jFrame) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    jFrame.setLocation((screenSize.width - jFrame.getSize().width) / 2,
            (screenSize.height - jFrame.getSize().height) / 2);
}

From source file:Main.java

public static void showFrame(JFrame frame, JFrame parent) {
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.pack();//from   w w  w . java2s. c  om
    frame.setLocation(parent.getX() + (parent.getWidth() - frame.getWidth()) / 2,
            parent.getY() + (parent.getHeight() - frame.getHeight()) / 2);
    frame.setVisible(true);
}

From source file:Main.java

public static void centerFrame(JFrame frame) {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((screenSize.width / 2) - (frameSize.width / 2),
            (screenSize.height / 2) - (frameSize.height / 2));
}

From source file:Main.java

/**
 * Center JFrame.//from  w  w  w  .  j av  a 2  s  .c  o m
 */
public static void center(JFrame frame) {
    Dimension frameSize = frame.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1);
}

From source file:Main.java

private static void centerOn(JFrame f, GraphicsConfiguration gc) {
    Rectangle bounds = gc.getBounds();
    int x = bounds.x + ((bounds.width - f.getWidth()) / 2);
    int y = bounds.y + ((bounds.height - f.getHeight()) / 2);
    f.setLocation(x, y);
}

From source file:Main.java

public static void setFrameCenter(JFrame frame) {

    int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    frame.setLocation((screenWidth - frame.getWidth()) / 2, (screenHeight - frame.getHeight()) / 2);

}

From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java

private static void moveCenter(JFrame frame) {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
}

From source file:Main.java

public static void center(JFrame mainWindow) {
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - mainWindow.getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - mainWindow.getHeight()) / 2);
    mainWindow.setLocation(x, y);
}

From source file:Main.java

public static void centerJFrame(JFrame jFrame) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int x = (screenSize.width - jFrame.getWidth()) / 2;
    int y = (screenSize.height - jFrame.getHeight()) / 2;
    jFrame.setLocation(x, y);
}