Example usage for java.awt Component setSize

List of usage examples for java.awt Component setSize

Introduction

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

Prototype

public void setSize(Dimension d) 

Source Link

Document

Resizes this component so that it has width d.width and height d.height .

Usage

From source file:pcgen.gui2.tools.Utility.java

/**
 * Update the size of the dialog to ensure it will fit on the screen.
 *
 * @param dialog The dialog to be resized.
 */// w ww. j  a v a  2 s. c  o  m
public static void resizeComponentToScreen(Component dialog) {
    // Get the maximum window size to account for taskbars etc
    Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

    final Dimension dialogSize = dialog.getSize();

    if (dialogSize.height > screenBounds.height) {
        dialogSize.height = screenBounds.height;
    }

    if (dialogSize.width > screenBounds.width) {
        dialogSize.width = screenBounds.width;
    }
    dialog.setSize(dialogSize);
}