Java Rectangle Bounds getLocalBounds(Rectangle bounds, Container c)

Here you can find the source of getLocalBounds(Rectangle bounds, Container c)

Description

This returns the "local" bounds of a component.

License

Open Source License

Parameter

Parameter Description
bounds rectangle to modify with the given component's bounds (will create new Rectangle if this is null)
c component to get the bounds from

Return

convenience reference to the rectangle passed in (or the created rectangle)

Declaration

public static Rectangle getLocalBounds(Rectangle bounds, Container c) 

Method Source Code


//package com.java2s;
import java.awt.Container;
import java.awt.Insets;
import java.awt.Rectangle;

public class Main {
    /**//from  ww  w .j ava2 s .  c  om
     * This returns the "local" bounds of a component.  This does the
     * same calculation as the method of the same name in
     * SwingUtilities, but this doesn't create a new Rectangle, but
     * instead overwrites the one passed in. 
     *
     * @param bounds rectangle to modify with the given component's
     * bounds (will create new Rectangle if this is null)
     * @param c component to get the bounds from 
     *
     * @return convenience reference to the rectangle passed in (or
     * the created rectangle) */
    public static Rectangle getLocalBounds(Rectangle bounds, Container c) {

        // Create a new Rectangle only if necessary.
        if (bounds == null)
            bounds = new Rectangle();

        // Get the insets of the components.
        Insets insets = c.getInsets();

        // Set the origin to (0,0) and the width and height to those
        // of the given component. 
        bounds.setBounds(0, 0, c.getWidth() - (insets.left + insets.right),
                c.getHeight() - (insets.top + insets.bottom));

        // Return the given rectangle (or the created one if this was
        // necessary). 
        return bounds;
    }
}

Related

  1. exportBounds(Frame theFame, Document doc)
  2. getBounds(Shape s)
  3. getBoundsInAncestor(Container ancestor, final Component comp, Rectangle bounds)
  4. getCenteredBoundsOn(Rectangle srcBounds, int width, int height)
  5. getLocalBounds(Component aComponent)
  6. getRectangleListBounds(Vector vctRectangles)
  7. isInCollision(Rectangle boundedBoxPlayer, Rectangle boundedBoxObject)
  8. setBounds(Container container, Component component, Rectangle bounds)
  9. setBounds(java.awt.Rectangle hole, int xA, int yA, int xB, int yB)