Here you can find the source of isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect)
public static boolean isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect)
//package com.java2s; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import java.awt.*; public class Main { public static boolean isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect) { Rectangle r = modelToView(scrollableComponent, pos); return intersects(r, visibleRect); }/*w w w. ja va 2s . c o m*/ private static Rectangle modelToView(final JTextComponent scrollableComponent, int pos) { try { return scrollableComponent.modelToView(pos); } catch (BadLocationException exception) { throw new RuntimeException(exception); } } private static boolean intersects(final Rectangle elementRect, final Rectangle viewportRect) { // check the location of the top of the element if ((elementRect.y < viewportRect.y) || (elementRect.y > viewportRect.y + viewportRect.height)) { return false; } // check the location of the bottom of the element if ((elementRect.y + elementRect.height < viewportRect.y) || (elementRect.y + elementRect.height > viewportRect.y + viewportRect.height)) { return false; } return true; } }