Java JComponent Size getVisibleSizeInViewport(Component c)

Here you can find the source of getVisibleSizeInViewport(Component c)

Description

get Visible Size In Viewport

License

Open Source License

Return

the visible size of a component in its viewport (including scrollbars)

Declaration

public static Dimension getVisibleSizeInViewport(Component c) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w  ww. j a va 2 s . c o  m*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.awt.Component;

import java.awt.Dimension;

import javax.swing.JScrollPane;

import javax.swing.JViewport;

public class Main {
    /**
     * @return the visible size of a component in its viewport (including
     *         scrollbars)
     */
    public static Dimension getVisibleSizeInViewport(Component c) {
        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;
        }
    }
}

Related

  1. getScreenSize(Component invoker)
  2. getSize(byte[] data)
  3. getSize(Component c, int sizeflag)
  4. getValidatedSize(Component c, int sizeflag)
  5. getViewableScreenSize()
  6. getWindowSize(JComponent start)
  7. inset(Component c, int insetSizeHor, int insetSizeVert)
  8. isSmallSizeVariant(JComponent c)
  9. makeEqualSize(JComponent reference, JComponent... others)