Here you can find the source of fitInScreen(Window o)
Parameter | Description |
---|---|
window | Window to fit in the screen |
public static void fitInScreen(Window o)
//package com.java2s; /*/*from w w w.j a v a 2 s . c om*/ The Martus(tm) free, social justice documentation and monitoring software. Copyright (C) 2001-2007, Beneficent Technology, Inc. (The Benetech Initiative). Martus 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 2 of the License, or (at your option) any later version with the additions and exceptions described in the accompanying Martus license file entitled "license.txt". It is distributed WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, including warranties of fitness of purpose or merchantability. See the accompanying Martus License and GPL license for more details on the required license terms for this software. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To the extent this copyrighted software code is used in the Miradi project, it is subject to a royalty-free license to members of the Conservation Measures Partnership when used with the Miradi software as specified in the agreement between Benetech and WCS dated 5/1/05. */ import java.awt.Dimension; import java.awt.Point; import java.awt.Toolkit; import java.awt.Window; public class Main { /** * Make sure that an on screen component fits on the screen without trying * to re-size it. This is good to apply to pop-ups after moving them. * * @param window Window to fit in the screen */ public static void fitInScreen(Window o) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Point oPoint = o.getLocation(); int oX = (int) oPoint.getX(); int oY = (int) oPoint.getY(); int outX = oX + o.getWidth(); int outY = oY + o.getHeight(); if (outX > screen.getWidth()) oX -= outX - screen.getWidth(); if (outY > screen.getHeight()) oY -= outY - screen.getHeight(); oX = Math.max(oX, 0); oY = Math.max(oY, 0); o.setLocation(oX, oY); } }