Example usage for java.awt Toolkit getScreenSize

List of usage examples for java.awt Toolkit getScreenSize

Introduction

In this page you can find the example usage for java.awt Toolkit getScreenSize.

Prototype

public abstract Dimension getScreenSize() throws HeadlessException;

Source Link

Document

Gets the size of the screen.

Usage

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);//from ww w .ja  v  a  2  s  . c  o  m
}

From source file:Main.java

/**
 * Position in center a JFrame//from   w ww.  j av a  2s. c o  m
 *
 * @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 window_centered(JFrame frame) {
    frame.pack();/*from  ww w . ja  v  a 2 s . c  o  m*/
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int width = screenSize.width;
    int height = screenSize.height;
    int x = (width - frame.getWidth()) / 2;
    int y = (height - frame.getHeight()) / 2;
    frame.setLocation(x, y);
}

From source file:Main.java

public static void setFrameRelativeSize(Window frame, int width, int height) {
    //Get the screen size
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();

    //Calculate the frame location
    frame.setSize(screenSize.width - width, screenSize.height - height);
}

From source file:Main.java

public static void setScreenCenter(Container container) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenDimension = toolkit.getScreenSize();
    int width = container.getWidth();
    int height = container.getHeight();
    Point point = new Point();
    point.setLocation((screenDimension.getWidth() - width) / 2, (screenDimension.getHeight() - height) / 2);
    container.setLocation(point);// w  w  w  .jav  a  2  s. co m
}

From source file:Main.java

/**
 * Center the given window within the screen boundaries.
 *
 * @param window the window to be centered.
 *//*from w ww  . j  a v a 2s.  co m*/
public static void centerWindow(Window window) {
    Rectangle bounds;
    try {
        bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration().getBounds();
    } catch (Throwable t) {
        Toolkit tk = window.getToolkit();
        Dimension ss = tk.getScreenSize();
        bounds = new Rectangle(ss);
    }

    int width = window.getWidth(), height = window.getHeight();
    window.setBounds(bounds.x + (bounds.width - width) / 2, bounds.y + (bounds.height - height) / 2, width,
            height);
}

From source file:Main.java

/**
 * Gauge the given component on screen./*from w w w  . j av  a2s.  co  m*/
 *
 * @param component Swing-component to gauge.
 */
public static void makeCentered(final Component component) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dim = toolkit.getScreenSize();
    int screenWidth = dim.width;
    int screenHeight = dim.height;
    component.setLocation((screenWidth - component.getSize().width) / 2,
            (screenHeight - component.getSize().height) / 2);
}

From source file:Main.java

public static Point getScreenCenterLocation(Window w) {
    Dimension size = w.getSize();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    double desktopHeight = toolkit.getScreenSize().getHeight();
    double desktopWidth = toolkit.getScreenSize().getWidth();

    // To the left (hack for Ngoc's dual display)
    if (desktopWidth > 1600) {
        desktopWidth += 1600;/*  w  ww . j  av a2 s  .  co  m*/
    }
    Point location = new Point();
    location.x = (int) (desktopWidth - size.getWidth()) / 2;
    location.y = (int) (desktopHeight - size.getHeight()) / 2;
    return location;
}

From source file:Main.java

/**
 * Returns a <code>Point</code> used as location for a window that
 * should be centered on the screen./*  w  ww.  j  a  va2s  .  co  m*/
 * 
 * @param size a <code>Dimension</code> describing the window's size
 * @return a <code>Point</code> describing the top-left position
 */
public static Point getCenteredLocation(Dimension size) {

    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension screenSize = tk.getScreenSize();

    return new Point(((screenSize.width - size.width) / 2), ((screenSize.height - size.height) / 2));
}

From source file:Main.java

public static void showDialog(JDialog d) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final int x = (screenSize.width - d.getWidth()) / 2;
    final int y = (screenSize.height - d.getHeight()) / 2;
    d.setLocation(x, y);//ww w.j  a  v  a 2 s  .c o m
    d.setVisible(true);
}