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

/**
 * Used for getting the actual bound of the monitor that contains Point p
 *
 * @param p - point to check monitor for
 * @return - current monitor bounds//  w w  w.  j  ava  2 s  .  co m
 */
public static Rectangle getScreenBoundsForPoint(Point p) {
    Rectangle bounds;
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

    GraphicsConfiguration graphicsConfiguration = null;
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd.getDefaultConfiguration().getBounds().contains(p)) {
            graphicsConfiguration = gd.getDefaultConfiguration();
            break;
        }
    }
    if (graphicsConfiguration != null) {
        bounds = graphicsConfiguration.getBounds();
        Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration);
        bounds.x += screenInsets.left;
        bounds.y += screenInsets.top;
        bounds.height -= screenInsets.bottom;
        bounds.width -= screenInsets.right;
    } else {
        bounds = env.getMaximumWindowBounds();
    }
    return (bounds);
}

From source file:Main.java

/**
 * <p><!-- Method description --></p>
 *
 *
 * @param frame//from w ww . j av  a  2 s .co  m
 */
public static void smartSetBounds(JFrame frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = 500;
    int height = 500;

    if (screenSize.height <= 600) {
        height = (int) (screenSize.height * .95);
    } else if (screenSize.height <= 1000) {
        height = (int) (screenSize.height * .90);
    } else if (screenSize.height <= 1200) {
        height = (int) (screenSize.height * .85);
    } else {
        height = (int) (screenSize.height * .80);
    }

    if (screenSize.width <= 1000) {
        width = (int) (screenSize.width * .95);
    } else if (screenSize.width <= 1200) {
        width = (int) (screenSize.width * .90);
    } else if (screenSize.width <= 1600) {
        width = (int) (screenSize.width * .85);
    } else {
        width = (int) (screenSize.width * .80);
    }

    frame.setBounds(0, 0, width, height);
}

From source file:Main.java

/**
 * Show an info window.//from   w  w w.j ava2  s  .co m
 * @param message   The message to show.
 * @param parent   Parent component of this dialog.
 */
public static void info(String message, Component parent) {
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(parent, message, "Info", JOptionPane.INFORMATION_MESSAGE);
}

From source file:Main.java

/**
 * Show an alert window.//  w  w w .  j  ava  2  s  . c o m
 * @param message   The message to show.
 * @param parent   Parent component of this dialog.
 */
public static void error(String message, Component parent) {
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(parent, message, "Alert", JOptionPane.ERROR_MESSAGE);
}

From source file:Main.java

/**
 * Show a warning window./*  w w w .  j  a v a2s. c  o  m*/
 * @param message   The message to show.
 * @param parent   Parent component of this dialog.
 */
public static void warning(String message, Component parent) {
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(parent, message, "Warning", JOptionPane.WARNING_MESSAGE);
}

From source file:Main.java

public static void moveToCenter(JFrame frame) {
    int windowWidth = frame.getWidth();
    int windowHeight = frame.getHeight();
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    frame.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);
}

From source file:Main.java

public static void setMaxSizePercent(final Component c, float widthPercent, float heightPercent) {
    final Dimension screenDimensions = Toolkit.getDefaultToolkit().getScreenSize();
    float fWidth = ((float) screenDimensions.width) * widthPercent;
    float fHeight = ((float) screenDimensions.height) * heightPercent;
    c.setMaximumSize(new Dimension((int) fWidth, (int) fHeight));
}

From source file:Main.java

public static void copyToClipboard(String s) {
    StringSelection stringSelection = new StringSelection(s);
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:Main.java

/**
 * Returns the current system EventQueue.
 */
private static EventQueue eventQueue() {
    return Toolkit.getDefaultToolkit().getSystemEventQueue();
}

From source file:Main.java

/**
 * Maximumiz both./*from   www.  ja  va2 s  . c o m*/
 *
 * @param window
 *            the window
 */
public static void maximumizBoth(final Window window) {
    if (window instanceof Frame) {
        final Frame frm = (Frame) window;
        frm.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else {
        window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    }

}