Java Utililty Methods Screen Full Size

List of utility methods to do Screen Full Size

Description

The list of methods to do Screen Full Size are organized into topic(s).

Method

voidbringWindowToScreen(Window window)
bring Window To Screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = (int) screenSize.getWidth();
int screenHeight = (int) screenSize.getHeight();
Dimension size = window.getSize();
int windowWidth = (int) size.getWidth();
int windowHeight = (int) size.getHeight();
Point locationOnScreen = window.getLocationOnScreen();
int left = (int) locationOnScreen.getX();
...
voidcentreInScreen(Container containee, int xOffSet, int yOffSet)
centre In Screen
Dimension screenSize = getDefaultScreenSize();
Dimension thisSize = containee.getSize();
int x = (int) (((screenSize.getWidth() - thisSize.width) / 2) + xOffSet);
if (x < 0)
    x = 0;
int y = (int) (((screenSize.getHeight() - thisSize.height) / 2) + yOffSet);
if (y < 0)
    y = 0;
...
voidcentrePositionOnScreen(Window window)
centre Position On Screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = window.getSize();
window.setLocation(screenSize.width - frameSize.width >> 1, screenSize.height - frameSize.height >> 1);
voidensureOnScreen(Container container)
ensure On Screen
if (container == null)
    return;
Point containerTopLeftHandCorner = container.getLocation();
Dimension containerSize = container.getSize();
Rectangle screenSize = getDefaultScreenSizeWithoutAdjustment();
int x = containerTopLeftHandCorner.x;
if (x < 0)
    x = 0;
...
voidensureWindowOnScreen(Window window)
Ensures that specified window do not exceed screen size, including possible task bar.
Toolkit kit = Toolkit.getDefaultToolkit();
GraphicsConfiguration gc = window.getGraphicsConfiguration();
Insets ins = kit.getScreenInsets(gc);
Dimension totalSize = kit.getScreenSize();
int availWidth = totalSize.width - ins.left - ins.right;
int availHeight = totalSize.height - ins.top - ins.bottom;
Point loc = window.getLocation();
Dimension size = window.getSize();
...
DimensionfactorScreenDimension(Window window, double widthFactor, double heightFactor)
Gets a dimension applying a width and/or height factor relative to the screen dimension.
Dimension d = getScreenSize(window);
d.width *= widthFactor;
d.height *= heightFactor;
return d;
voidfitInScreen(Component comp)
fit In Screen
Rectangle maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
Rectangle compBounds = comp.getBounds();
Rectangle newBounds = new Rectangle(Math.max(compBounds.x, maxBounds.x),
        Math.max(compBounds.y, maxBounds.y), Math.min(compBounds.width, maxBounds.width - maxBounds.y),
        Math.min(compBounds.height, maxBounds.height - maxBounds.y));
if (newBounds.x + newBounds.width > maxBounds.width) {
    newBounds.x = Math.max(maxBounds.x, maxBounds.width - newBounds.width);
if (newBounds.y + newBounds.height > maxBounds.height) {
    newBounds.y = Math.max(maxBounds.y, maxBounds.height - newBounds.height);
if (!newBounds.equals(compBounds)) {
    comp.setBounds(newBounds);
voidfitInScreen(Window o)
Make sure that an on screen component fits on the screen without trying to re-size it.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Point oPoint = o.getLocation();
int oX = (int) oPoint.getX();
int oY = (int) oPoint.getY();
int outX = oX + o.getWidth();
int outY = oY + o.getHeight();
if (outX > screen.getWidth())
    oX -= outX - screen.getWidth();
...
DimensionfitToScreen(Dimension size, GraphicsConfiguration screen)
Returns a new size where width and height are the minimum of the given size and the available screen space.
Dimension resizedSize = new Dimension();
Dimension displaySize = screen.getBounds().getSize();
Insets displayInsets = Toolkit.getDefaultToolkit().getScreenInsets(screen);
resizedSize.width = Math.min(size.width, displaySize.width - displayInsets.left - displayInsets.right);
resizedSize.height = Math.min(size.height, displaySize.height - displayInsets.top - displayInsets.bottom);
return resizedSize;
voidforceToScreen(Window window)
Reposition the specified window so that it necessarily fits on the screen, while trying to minimize changes.
Dimension screenSize = window.getToolkit().getScreenSize();
Rectangle bounds = window.getBounds();
bounds.width = Math.min(bounds.width, screenSize.width);
bounds.height = Math.min(bounds.height, screenSize.height);
bounds.x = Math.min(Math.max(bounds.x, 0), screenSize.width - bounds.width);
bounds.y = Math.min(Math.max(bounds.y, 0), screenSize.height - bounds.height);
window.setBounds(bounds);