Java JComponent Size contentSize(final Component component)

Here you can find the source of contentSize(final Component component)

Description

Returns component content size limited by component border.

License

Open Source License

Parameter

Parameter Description
component component to process

Return

component content size rectangle

Declaration

public static Rectangle contentSize(final Component component) 

Method Source Code


//package com.java2s;
/*//from   w w w.j a v  a  2 s .  com
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library 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.
 *
 * WebLookAndFeel library 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 WebLookAndFeel library.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.*;

import java.awt.*;

public class Main {
    /**
     * Returns component content size limited by component border.
     *
     * @param component component to process
     * @return component content size rectangle
     */
    public static Rectangle contentSize(final Component component) {
        if (component instanceof JComponent) {
            final Insets i = ((JComponent) component).getInsets();
            return new Rectangle(i.left, i.top, component.getWidth() - i.left - i.right,
                    component.getHeight() - i.top - i.bottom);
        } else {
            return size(component);
        }
    }

    /**
     * Returns component size represented as a rectangle with zero X and Y coordinates.
     *
     * @param component component to process
     * @return component size rectangle
     */
    public static Rectangle size(final Component component) {
        return new Rectangle(0, 0, component.getWidth(), component.getHeight());
    }
}

Related

  1. addWithSize(Component c, int width, int height)
  2. adjustWindowToMinimumSize(final Window window)
  3. autoFitResize(final JLayeredPane pane, final Component... comps)
  4. changeSize(JComponent comp, float newSize)
  5. createDoubleSpinner(final double value, final double rangeMinimum, final double rangeMaximum, final double stepSize, final double bigStepSize, final String formatPattern)
  6. differsSize(AttributeSet style, AttributeSet base)
  7. doSetSize(final Component component, final int width, final int height)
  8. doSetSizeInEDT(final Component component, final int width, final int height)