Java Screen Size setWindowSize(final Window w, final Rectangle r)

Here you can find the source of setWindowSize(final Window w, final Rectangle r)

Description

set Window Size

License

Open Source License

Declaration

public static void setWindowSize(final Window w, final Rectangle r) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Rectangle;
import java.awt.Window;

public class Main {
    public static void setWindowSize(final Window w, final Rectangle r) {
        final Toolkit kit = Toolkit.getDefaultToolkit();
        final Dimension dim = kit.getScreenSize();
        if (r.x < 0 || r.x > dim.width) {
            r.x = 0;/* www. ja  va2  s  . c o  m*/
        }
        if (r.y < 0 || r.y > dim.height) {
            r.y = 0;
        }
        if (r.width < 50) {
            r.width = 50;
        }
        if (r.height < 50) {
            r.height = 50;
        }
        r.width = Math.min(r.width, (int) (dim.width * 0.99));
        r.height = Math.min(r.height, (int) (dim.height * 0.99));
        w.setBounds(r);
        if (w instanceof Frame) {
            ((Frame) w).setState(0);
        }
    }
}

Related

  1. screenSize()
  2. setLocationRelativeToAndSizeToWindow(Component parent, Component child, Dimension max)
  3. setSize(final Window window, final int minusX, final int minusY)
  4. setSize(Window window, double widthFactor, double heightFactor)
  5. setWindowDesktopSize(Window window, double sizeX, double sizeY)
  6. sizeForScreen(Component component)