Java Utililty Methods JComponent Size

List of utility methods to do JComponent Size

Description

The list of methods to do JComponent Size are organized into topic(s).

Method

DimensiongetSize(byte[] data)
get Size
ImageIcon ii = new ImageIcon(data);
Image img = ii.getImage();
return new Dimension(img.getWidth(null), img.getHeight(null));
DimensiongetSize(Component c, int sizeflag)
get Size
if (c == null) {
    return new Dimension(0, 0);
if (c instanceof JLabel) {
    View v = (View) ((JLabel) c).getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
    if (v != null) {
        switch (sizeflag) {
        case MIN: {
...
DimensiongetValidatedSize(Component c, int sizeflag)
get Validated Size
return getValidatedSizes(c)[sizeflag];
DimensiongetViewableScreenSize()
get Viewable Screen Size
Dimension screenSizeExcludingToolbars = Toolkit.getDefaultToolkit().getScreenSize();
Insets insets = getSystemInsets();
screenSizeExcludingToolbars.width -= (insets.left + insets.right);
screenSizeExcludingToolbars.height -= (insets.top + insets.bottom);
return screenSizeExcludingToolbars;
DimensiongetVisibleSizeInViewport(Component c)
get Visible Size In Viewport
if (c.getParent() instanceof JViewport) {
    JViewport vp = (JViewport) c.getParent();
    Dimension d = vp.getExtentSize();
    if (vp.getParent() instanceof JScrollPane) {
        JScrollPane sp = (JScrollPane) vp.getParent();
        if (sp.getVerticalScrollBar() != null && sp.getVerticalScrollBar().isVisible()) {
            d.width += sp.getVerticalScrollBar().getWidth();
        if (sp.getHorizontalScrollBar() != null && sp.getHorizontalScrollBar().isVisible()) {
            d.height += sp.getHorizontalScrollBar().getHeight();
    return d;
} else {
    return null;
DimensiongetWindowSize(JComponent start)
return the size of the window
return getTopAncestor(start).getSize();
JPanelinset(Component c, int insetSizeHor, int insetSizeVert)
Inset the given component by the given insetSize for horizontally and vertically.
return doLayout(new JPanel(), new Component[] { c }, 1, WT_Y, WT_Y, null, null,
        new Insets(insetSizeVert, insetSizeHor, insetSizeVert, insetSizeHor));
booleanisSmallSizeVariant(JComponent c)
Returns true, if the component should use the small appearance.
Font f = c.getFont();
if (f != null && f.getSize() <= 11) {
    return true;
String p = (String) c.getClientProperty("JComponent.sizeVariant");
return p != null && p.equals("small");
voidmakeEqualSize(JComponent reference, JComponent... others)
make Equal Size
if (reference == null)
    return;
if (others == null)
    return;
Dimension size = reference.getPreferredSize();
for (JComponent comp : others) {
    comp.setPreferredSize(size);
voidmakeSameSize(Component... components)
make Same Size
makeSameHeight(components);
makeSameWidth(components);