Example usage for java.awt Window setMinimumSize

List of usage examples for java.awt Window setMinimumSize

Introduction

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

Prototype

public void setMinimumSize(Dimension minimumSize) 

Source Link

Document

Sets the minimum size of this window to a constant value.

Usage

From source file:Main.java

/**
 * This method packs, sets the size, and sets the position of the window given
 *
 * @param window/*from   ww w .j  a  va 2  s.  co m*/
 */
public static void centerAndPack(Window window) {
    window.pack();
    int x = getWindowXCenter() - (window.getWidth() / 2);
    int y = getWindowYCenter() - (window.getHeight() / 2);
    window.setLocation(x, y);
    window.setMinimumSize(new Dimension(window.getWidth(), window.getHeight()));
}

From source file:Main.java

public static void centerWindow(Window window, int width, int height) {
    // Get screen size
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension screensize = tk.getScreenSize();

    // Set window minimum size
    window.setMinimumSize(new Dimension((int) Math.floor(screensize.getWidth() * 0.3),
            (int) Math.floor(screensize.getHeight() * 0.3)));

    // Set window size
    if (width == 0f)
        width = (int) Math.floor(screensize.getWidth() * 0.8);

    if (height == 0f)
        height = (int) Math.floor(screensize.getHeight() * 0.8);

    window.setPreferredSize(new Dimension(width, height));

    int left = (int) (screensize.getWidth() - width) / 2;
    int right = (int) (screensize.getHeight() - height) / 2;
    ;// w ww.ja va  2 s . co m

    // Center window
    window.setLocation(left, right);
}

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.
 *//*from w w w  .jav a2  s  .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);
}