/// <summary> /// Gets the sub-rectangle of a JScrollPane's area that /// is actually showing the view /// </summary> private Rectangle getShowingRect(JScrollPane pane) { Insets ins1 = pane.Viewport.Insets; Border inner = pane.ViewportBorder; Insets ins2; if (inner != null) { ins2 = inner.getBorderInsets(pane); } else { ins2 = new Insets(0, 0, 0, 0); } Insets ins3 = new Insets(0, 0, 0, 0); if (pane.Border != null) { ins3 = pane.Border.getBorderInsets(pane); } Rectangle r = pane.ViewportBorderBounds; r.translate(-r.x, -r.y); r.width -= ins1.left + ins1.right; r.width -= ins2.left + ins2.right; r.height -= ins1.top + ins1.bottom; r.height -= ins2.top + ins2.bottom; r.x -= ins2.left; r.x -= ins3.left; Point p = pane.Viewport.ViewPosition; r.translate(p.x, p.y); r = SwingUtilities.convertRectangle(pane.Viewport, r, pane); return(r); }