get Maximum Window Bounds - Java Swing

Java examples for Swing:Screen

Description

get Maximum Window Bounds

Demo Code


//package com.java2s;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;

import java.lang.reflect.Method;

public class Main {
    public static Rectangle getMaximumWindowBounds() {
        try {//  w  ww .  j  a va 2s  .  c  om
            GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment
                    .getLocalGraphicsEnvironment();
            Method method = GraphicsEnvironment.class
                    .getMethod("getMaximumWindowBounds");
            return (Rectangle) method.invoke(localGraphicsEnvironment);
        } catch (Exception e) {
            Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
            return new Rectangle(0, 0, s.width, s.height);
        }

    }
}

Related Tutorials