Java Screen Full Size bringWindowToScreen(Window window)

Here you can find the source of bringWindowToScreen(Window window)

Description

bring Window To Screen

License

Apache License

Declaration

public static void bringWindowToScreen(Window window) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.*;

public class Main {
    public static void bringWindowToScreen(Window window) {
        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();
        int top = (int) locationOnScreen.getY();

        if (screenWidth < left + windowWidth) {
            left = screenWidth - windowWidth;
        }//ww w  .  j  a va 2  s .  com

        if (screenHeight < top + windowHeight) {
            top = screenHeight - windowHeight;
        }

        window.setLocation(left, top);
    }
}

Related

  1. centreInScreen(Container containee, int xOffSet, int yOffSet)
  2. centrePositionOnScreen(Window window)
  3. ensureOnScreen(Container container)
  4. ensureWindowOnScreen(Window window)