Java Screen Full Size fitInScreen(Component comp)

Here you can find the source of fitInScreen(Component comp)

Description

fit In Screen

License

Open Source License

Declaration

public static void fitInScreen(Component comp) 

Method Source Code

//package com.java2s;
/**************************************************************************
 OmegaT - Computer Assisted Translation (CAT) tool 
  with fuzzy matching, translation memory, keyword search, 
  glossaries, and translation leveraging into updated projects.
    // w w  w .j ava 2s .co m
 Copyright (C) 2006 Henry Pijffers
       2013 Yu Tang
       2014-2015 Aaron Madlon-Kay
       Home page: http://www.omegat.org/
       Support center: http://groups.yahoo.com/group/OmegaT/
    
 This file is part of OmegaT.
    
 OmegaT 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.
    
 OmegaT 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.Component;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

public class Main {
    public static void fitInScreen(Component comp) {
        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);
        }
    }
}

Related

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