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 setClipboardText(String str) {
    Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection selection = new StringSelection(str);
    clipBoard.setContents(selection, null);
}

From source file:Main.java

public static void centerFrame(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 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 w w. j a  va2 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

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

/** GUI utility (set frame on the center of screen) */
public static void setCenter(Window w) {
    Dimension scSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension wndSize = w.getSize();
    w.setLocation((scSize.width - wndSize.width) / 2, (scSize.height - wndSize.height) / 2);
}

From source file:Main.java

public static String getClipboard() {
    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    try {//from w w w .  j a v  a 2  s . c  o m
        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String) t.getTransferData(DataFlavor.stringFlavor);

            return text.trim();
        }
    } catch (Exception e) {
    }
    return "";
}

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 final void fullScreen(Component component) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = component.getSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }/*from w ww. j  a v a2 s.c om*/

    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 centerFrame(JFrame frame, Preferences prefs, int defWidth, int defHeight) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int w = (int) ((screenSize.getWidth() / 100) * defWidth);
    int h = (int) ((screenSize.getHeight() / 100) * defHeight);
    int x = (int) ((screenSize.getWidth() - w) / 2);
    int y = (int) ((screenSize.getHeight() - h) / 2);
    if (prefs != null) {
        frame.setBounds(prefs.getInt("x", x), prefs.getInt("y", y), prefs.getInt("w", w), prefs.getInt("h", h));
    } else {/*from  w  w w .  j a v a  2 s.c om*/
        frame.setBounds(x, y, w, h);
    }
}

From source file:Main.java

public static Point 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   ww w. j a va 2  s  . c  o m*/
        newComponentX = 0;
    int newComponentY = screenSize.height - componentSize.height;
    if (newComponentY >= 0)
        newComponentY = newComponentY / 2;
    else
        newComponentY = 0;
    Point location = new Point(newComponentX, newComponentY);
    component.setLocation(location);
    return location;
}