Example usage for java.awt Window setSize

List of usage examples for java.awt Window setSize

Introduction

In this page you can find the example usage for java.awt Window setSize.

Prototype

public void setSize(Dimension d) 

Source Link

Document

The d.width and d.height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:Main.java

/**
 * Enlarges a window to its preferred width and/or height if it is too small.
 *///from  w  ww .  ja v a2s.co m
public static void repack(final Window w) {
    final Dimension size = getRepackSize(w);
    if (!w.getSize().equals(size))
        w.setSize(size);
}

From source file:Main.java

/**
 * Maximumiz both./*from w ww. ja  v  a 2s .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());
    }

}

From source file:Main.java

public static void pack(Component c) {
    Window window = getFrame(c);
    window.pack();/*from w  w w .j av  a2s  . c o m*/
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension bounds = new Dimension();
    bounds.width = Math.min(window.getWidth(), screenSize.width * 8 / 10);
    bounds.height = Math.min(window.getHeight(), screenSize.height * 8 / 10);
    window.setSize(bounds);
}

From source file:Main.java

public static void center(Window frame, int left, int right, int top, int bottom) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > (screenSize.height - top - bottom)) {
        frameSize.height = screenSize.height - top - bottom;
    }/*  w w  w . j ava 2s .c  om*/
    if (frameSize.width > screenSize.width - left - right) {
        frameSize.width = screenSize.width - left - right;
    }
    if (!frameSize.equals(frame.getSize())) {
        frame.setSize(frameSize);
    }
    frame.setLocation(left + (screenSize.width - frameSize.width) / 2,
            top + (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

static public void centerOnParent(final Window child, final boolean absolute) {
    child.pack();/*from  w  w w .  ja v  a 2s  . c o  m*/
    boolean useChildsOwner = child.getOwner() != null
            ? ((child.getOwner() instanceof JFrame) || (child.getOwner() instanceof JDialog))
            : false;
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension parentSize = useChildsOwner ? child.getOwner().getSize() : screenSize;
    final Point parentLocationOnScreen = useChildsOwner ? child.getOwner().getLocationOnScreen()
            : new Point(0, 0);
    final Dimension childSize = child.getSize();
    childSize.width = Math.min(childSize.width, screenSize.width);
    childSize.height = Math.min(childSize.height, screenSize.height);
    child.setSize(childSize);
    int x;
    int y;
    if ((child.getOwner() != null) && child.getOwner().isShowing()) {
        x = (parentSize.width - childSize.width) / 2;
        y = (parentSize.height - childSize.height) / 2;
        x += parentLocationOnScreen.x;
        y += parentLocationOnScreen.y;
    } else {
        x = (screenSize.width - childSize.width) / 2;
        y = (screenSize.height - childSize.height) / 2;
    }
    if (!absolute) {
        x /= 2;
        y /= 2;
    }
    child.setLocation(x, y);
}

From source file:net.pms.newgui.components.WindowProperties.java

/**
 * Creates a new instance using the specified parameters.
 *
 * @param window the {@link Window} whose properties to keep track of.
 * @param standardSize the standard size of {@code window}.
 * @param mimimumSize the minimum size of {@code window}.
 * @param windowConfiguration the {@link WindowPropertiesConfiguration}
 *            instance for reading and writing the window properties.
 *//* w  ww. j a v a 2s.  c  o  m*/
public WindowProperties(@Nonnull Window window, @Nullable Dimension standardSize,
        @Nullable Dimension mimimumSize, @Nullable WindowPropertiesConfiguration windowConfiguration) {
    if (window == null) {
        throw new IllegalArgumentException("window cannot be null");
    }
    this.window = window;
    this.minimumSize = mimimumSize;
    if (mimimumSize != null) {
        window.setMinimumSize(mimimumSize);
    }
    this.windowConfiguration = windowConfiguration;
    if (windowConfiguration != null) {
        getConfiguration();
        GraphicsConfiguration windowGraphicsConfiguration = window.getGraphicsConfiguration();
        if (windowBounds != null && effectiveScreenBounds != null && graphicsDevice != null
                && graphicsDevice.equals(windowGraphicsConfiguration.getDevice().getIDstring())
                && screenBounds != null && screenBounds.equals(windowGraphicsConfiguration.getBounds())) {
            setWindowBounds();
        } else {
            Rectangle screen = effectiveScreenBounds != null ? effectiveScreenBounds
                    : windowGraphicsConfiguration.getBounds();
            if (standardSize != null && screen.width >= standardSize.width
                    && screen.height >= standardSize.height) {
                window.setSize(standardSize);
            } else if (mimimumSize != null && (window.getWidth() < mimimumSize.width
                    || window.getHeight() < mimimumSize.getHeight())) {
                window.setSize(mimimumSize);
            }
            window.setLocationByPlatform(true);
        }
        if (window instanceof Frame) {
            // Set maximized state
            int maximizedState = windowState & Frame.MAXIMIZED_BOTH;
            if (maximizedState != 0) {
                ((Frame) window).setExtendedState(((Frame) window).getExtendedState() | maximizedState);
            }
        }
    }
    window.addWindowListener(this);
    window.addComponentListener(this);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Center and make the window visible//from  ww  w  .  j  av  a 2s  . c om
 * @param window the window to center
 * @param width sets the dialog to this width (can be null)
 * @param height sets the dialog to this height (can be null)
 */
public static void centerWindow(final java.awt.Window window, final Integer width, final Integer height) {
    JFrame topFrame = (JFrame) UIRegistry.getTopWindow();
    Insets screenInsets = null;
    Rectangle screenRect = null;

    if (width != null || height != null) {
        Dimension s = window.getSize();
        if (width != null)
            s.width = width;
        if (height != null)
            s.height = height;
        window.setSize(s);
    }

    // if there is a registered TOPFRAME, and it's not the same as the window being passed in...
    if (topFrame != null && topFrame != window) {
        screenRect = topFrame.getBounds();
        screenInsets = topFrame.getInsets();
    } else {
        screenRect = window.getGraphicsConfiguration().getBounds();
        screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());
    }

    // Make sure we don't place the demo off the screen.
    int centerWidth = screenRect.width < window.getSize().width ? screenRect.x
            : screenRect.x + screenRect.width / 2 - window.getSize().width / 2;
    int centerHeight = screenRect.height < window.getSize().height ? screenRect.y
            : screenRect.y + screenRect.height / 2 - window.getSize().height / 2;

    centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight;

    window.setLocation(centerWidth, centerHeight);
}