Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

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

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:Main.java

public static void centerFrame(Frame frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }/*from w  ww.j a va 2  s . c o m*/
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

public static final void defaultSize(Component component) {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = new Dimension((int) (screen.getWidth() * 2 / 3), (int) (screen.getHeight() * 0.8));
    component.setSize(size);/*from w ww  .j  ava2s .  co m*/
}

From source file:Main.java

static void setFramePositon(JFrame inTargetFrame) {

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = inTargetFrame.getSize();

    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
        inTargetFrame.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {//from   w  ww  . ja  v  a2s  .c o m
        inTargetFrame.setLocation(0, 0);
        inTargetFrame.setSize(d);
    }
}

From source file:Main.java

public static void setToScreenCenter(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();
    if (windowSize.height > screenSize.height) {
        windowSize.height = screenSize.height;
    }//from w  w w  .ja v a  2s.com
    if (windowSize.width > screenSize.width) {
        windowSize.width = screenSize.width;
    }
    window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2);
}

From source file:Main.java

public static Rectangle getScreenSize() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    return new Rectangle(0, 0, d.width, d.height);
}

From source file:Main.java

public static void ShowWindowAtScreenCenter(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//www.jav a  2  s  .  c  om
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    //      window.setVisible(true);
}

From source file:Main.java

public static final void center(Component component) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = component.getSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }/*from w  w w.j a  v a 2  s. com*/

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    component.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

public static void moveToScreenCenter(Component component) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension componentSize = component.getSize();
    int newComponentX = screenSize.width - componentSize.width;
    if (newComponentX >= 0)
        newComponentX = newComponentX / 2;
    else/*from w ww  .j  a  v a  2s  . c  om*/
        newComponentX = 0;
    int newComponentY = screenSize.height - componentSize.height;
    if (newComponentY >= 0)
        newComponentY = newComponentY / 2;
    else
        newComponentY = 0;
    component.setLocation(newComponentX, newComponentY);
}

From source file:Main.java

public static void fullWindow(Frame frame) {
    //      Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setSize(dim.width, dim.height);

    // Move the window
    frame.setLocation(0, 0);//from  w  w  w . j a v  a  2s.co  m
}

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