Here you can find the source of getScrollPaneViewportSize(JScrollPane panel)
public static final Rectangle getScrollPaneViewportSize(JScrollPane panel)
//package com.java2s; import java.awt.Rectangle; import javax.swing.JScrollBar; import javax.swing.JScrollPane; public class Main { public static final Rectangle getScrollPaneViewportSize(JScrollPane panel) { Rectangle viewRect = panel.getViewportBorderBounds(); JScrollBar vbar = panel.getVerticalScrollBar(); if (vbar.isVisible()) { viewRect.width = viewRect.width + vbar.getWidth(); }//w ww .ja va 2s . c o m JScrollBar hbar = panel.getHorizontalScrollBar(); if (hbar.isVisible()) { viewRect.height = viewRect.height + hbar.getHeight(); } return viewRect; } }