Get the bounds of the parent of the dragged component. - Java Swing

Java examples for Swing:JComponent

Description

Get the bounds of the parent of the dragged component.

Demo Code

/*//from   w  w w  .  j a v  a2  s  . co m
 * Copyright (C) 2011 Trilarion
 *
 * 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/>.
 */
//package com.java2s;

import java.awt.Component;

import java.awt.Dimension;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

import java.awt.Window;

public class Main {
    /**
     * Get the bounds of the parent of the dragged component.
     *
     * @param source
     * @return
     */
    public static Dimension getBoundingSize(Component source) {
        if (source instanceof Window) {
            GraphicsEnvironment env = GraphicsEnvironment
                    .getLocalGraphicsEnvironment();
            Rectangle bounds = env.getMaximumWindowBounds();
            return new Dimension(bounds.width, bounds.height);
        } else {
            return source.getParent().getSize();
        }
    }
}

Related Tutorials