Here you can find the source of contentSize(final Component component)
Parameter | Description |
---|---|
component | component to process |
public static Rectangle contentSize(final Component component)
//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()); } }