Example usage for java.awt Dimension getWidth

List of usage examples for java.awt Dimension getWidth

Introduction

In this page you can find the example usage for java.awt Dimension getWidth.

Prototype

public double getWidth() 

Source Link

Usage

From source file:Main.java

/**
 * Centers a given window on the screen.
 * //w  ww  .  j a  v a 2s  . c  o  m
 * @param window
 *            The window, frame or dialog
 */
public static void centerOnScreen(Window window) {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((d.getWidth() - window.getWidth()) / 2);
    int y = (int) ((d.getHeight() - window.getHeight()) / 2);
    window.setLocation(x, y);
}

From source file:Main.java

public static void center(JFrame mainWindow) {
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - mainWindow.getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - mainWindow.getHeight()) / 2);
    mainWindow.setLocation(x, y);//from  ww w . j a  v  a 2 s .  c om
}

From source file:UIUtilities.java

public static void setFrameLocationRelativeTo(JFrame f, Component c) {
    if (c == null) {
        // Setting the position of the dialog on the center of the screen
        // in 1.4 should be replaced by
        //             f.setLocationRelativeTo(null);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        f.setLocation((int) d.getWidth() / 2 - (int) f.getPreferredSize().getWidth() / 2,
                (int) d.getHeight() / 2 - (int) f.getPreferredSize().getHeight() / 2);
    }//  ww  w.ja v  a 2 s.c  om
}

From source file:Main.java

/**
 * Gets the max window size.//from   w w w.j a  v  a2 s .c o  m
 *
 * @return the max window size
 */
public static Dimension getMaxWindowSize() {
    final Dimension d = getScreenDimesion();
    return new Dimension((int) d.getWidth() - 100, (int) d.getHeight() - 100);
}

From source file:Main.java

public static void setLocationRelativeTo(Window child, Window parent) {
    Dimension d = parent.getSize();
    Dimension u = child.getSize();
    child.setLocation((int) ((d.getWidth() / 2) - (u.getWidth() / 2)),
            (int) ((d.getHeight() / 2) - (u.getHeight() / 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 {// w w  w . ja va 2 s .  c o m
        frame.setBounds(x, y, w, h);
    }
}

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  a  va  2s .com
}

From source file:Main.java

/**
 * Sets the size of the window to a width and height factor of the screen size.
 * //from  w  w  w . j a v a 2s .  c  o  m
 * @param window The window to set the size.
 * @param widthFactor The width factor of the screen size.
 * @param heightFactor The height factor of the screen size.
 */
public static void setSize(Window window, double widthFactor, double heightFactor) {
    Dimension screenSize = getScreenSize(window);
    int width = (int) (screenSize.getWidth() * widthFactor);
    int height = (int) (screenSize.getHeight() * heightFactor);
    window.setSize(width, height);
}

From source file:Main.java

/**
 * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any.
 *///from w w  w .  j a v a2s  . c om
public static void tieButtonSizes(List<JButton> buttons) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (JButton button : buttons) {
        Dimension buttonSize = button.getPreferredSize();
        maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth);
        maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight);
    }
    Dimension maxButtonSize = new Dimension(maxWidth, maxHeight);
    for (JButton button : buttons) {
        // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size.
        button.setPreferredSize(maxButtonSize);
        button.setMinimumSize(maxButtonSize);
        button.setMaximumSize(maxButtonSize);
        button.setSize(maxButtonSize);
    }
}

From source file:Main.java

public static Cursor buildCursorByTrimming(Toolkit toolkit, Image image, int x, int y, String name,
        Cursor defaultCursor) {/*from  ww w . ja v  a  2  s  .c o m*/
    Dimension d = toolkit.getBestCursorSize(image.getWidth(null), image.getHeight(null));
    if (d == null || d.getWidth() <= 0 || d.getHeight() <= 0)
        return defaultCursor;
    BufferedImage out = new BufferedImage((int) d.getWidth(), (int) d.getHeight(), BufferedImage.TYPE_INT_ARGB);
    out.getGraphics().drawImage(image, 0, 0, null);
    return toolkit.createCustomCursor(out, new Point(x, y), name);
}