Java Screen Full Size factorScreenDimension(Window window, double widthFactor, double heightFactor)

Here you can find the source of factorScreenDimension(Window window, double widthFactor, double heightFactor)

Description

Gets a dimension applying a width and/or height factor relative to the screen dimension.

License

Open Source License

Parameter

Parameter Description
window The window.
widthFactor The width factor relative to the screen (0 < factor <= 1).
heightFactor The height factor relative to the screen (0 < factor <= 1).

Return

The screen dimension.

Declaration

public static Dimension factorScreenDimension(Window window, double widthFactor, double heightFactor) 

Method Source Code

//package com.java2s;
/*//from   ww w .j  a va 2s  . co  m
 * Copyright (C) 2015 Miquel Sas
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.awt.Dimension;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import java.awt.Window;

public class Main {
    /**
     * Gets a dimension applying a width and/or height factor relative to the screen dimension.
     * 
     * @param window The window.
     * @param widthFactor The width factor relative to the screen (0 &lt; factor &lt;= 1).
     * @param heightFactor The height factor relative to the screen (0 &lt; factor &lt;= 1).
     * @return The screen dimension.
     */
    public static Dimension factorScreenDimension(Window window, double widthFactor, double heightFactor) {
        Dimension d = getScreenSize(window);
        d.width *= widthFactor;
        d.height *= heightFactor;
        return d;
    }

    /**
     * Returns the size of the screen containing the argument window or the primary screen if current window is not
     * selected.
     * 
     * @param window The window.
     * @return The screen size.
     */
    public static Dimension getScreenSize(Window window) {
        return getGraphicsDevice(window).getConfigurations()[0].getBounds().getSize();
    }

    /**
     * Returns the graphics device that should apply to a window.
     * 
     * @param window The window.
     * @return The graphics device.
     */
    public static GraphicsDevice getGraphicsDevice(Window window) {
        if (window != null) {
            return window.getGraphicsConfiguration().getDevice();
        }
        return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    }
}

Related

  1. bringWindowToScreen(Window window)
  2. centreInScreen(Container containee, int xOffSet, int yOffSet)
  3. centrePositionOnScreen(Window window)
  4. ensureOnScreen(Container container)
  5. ensureWindowOnScreen(Window window)
  6. fitInScreen(Component comp)
  7. fitInScreen(Window o)
  8. fitToScreen(Dimension size, GraphicsConfiguration screen)
  9. forceToScreen(Window window)