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 resizeToScreenProportions(Component component, double xProportion, double yProportion) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension componentNewSize = new Dimension((int) (screenSize.width * yProportion),
            (int) (screenSize.height * xProportion));
    component.setSize(componentNewSize);
}

From source file:Main.java

public static void centerOnScreen(final Window window) {
    final Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension windowSize = window.getSize();

    final int x = (screensize.width - windowSize.width) / 2;
    final int y = (screensize.height - windowSize.height) / 2;

    window.setLocation(x, y);//from   w w  w . ja v a  2  s.c  o m
}

From source file:Main.java

public static final void centerOnScreen(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();

    if (windowSize.height > screenSize.height)
        windowSize.height = screenSize.height;

    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

/**
 * Position in center a JFrame//from w ww .  ja v a 2  s .  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

/**
 * Get an empty cursor/*  w w  w.  j a v a2  s .c  om*/
 * 
 * @return
 */
public static Cursor createEmptyCursor() {
    Image cursorImage = Toolkit.getDefaultToolkit().createImage(new byte[] {});
    return Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "cursor");
}

From source file:Main.java

public static void copyToSystemClipboard(String str) {
    StringSelection ss = new StringSelection(str);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
}

From source file:Main.java

public static void center(Window window) {
    final Dimension size = window.getSize();
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    final int locX = (screen.width - size.width) / 2;
    final int locY = (screen.height - size.height) / 2;
    window.setLocation(locX, locY);/* ww  w .j  a  v a2  s  .  co  m*/
}

From source file:Main.java

/**
 * /*from w w  w.  java 2s  . c o  m*/
 * @param component
 */
public static void setMiniSize(JFrame component) {
    Dimension size = new Dimension();

    size.height = (int) (Toolkit.getDefaultToolkit().getScreenSize().height / 4);
    size.width = (int) (Toolkit.getDefaultToolkit().getScreenSize().width / 4);

    component.setMinimumSize(size);
}

From source file:Main.java

/**
 * Centers the component on the screen/*  ww  w  . j av a  2s. c o m*/
 */
public static void centerOnScreen(Component comp) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    comp.setLocation((screenSize.width - comp.getWidth()) / 2, (screenSize.height - comp.getHeight()) / 2);
}

From source file:Main.java

public static Insets getScreenInsets(Window win) {
    Insets si;//from w  w w  .ja  v a 2 s  .c  o  m
    if (win == null) {
        si = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration());
    } else {
        si = win.getToolkit().getScreenInsets(win.getGraphicsConfiguration());
    }
    return si;
}