Here you can find the source of getVisibleSizeInViewport(Component c)
public static Dimension getVisibleSizeInViewport(Component c)
//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; } } }