Java JTextComponent isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect)

Here you can find the source of isCompletelyVisible(final JTextComponent scrollableComponent, final int pos, final Rectangle visibleRect)

Description

is Completely Visible

License

Open Source License

Declaration

public static boolean isCompletelyVisible(final JTextComponent scrollableComponent, final int pos,
            final Rectangle visibleRect) 

Method Source Code


//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;
    }
}

Related

  1. highlighterIsNext(JTextComponent textComponent, boolean forwards, Highlighter.Highlight highlight)
  2. implyDisabled(final JCheckBox checked, final boolean checkedState, final JTextComponent changed)
  3. inScrollPane(JTextComponent textComponent, boolean autoscroll)
  4. installUi(JTextComponent txt)
  5. installUndoManager(JTextComponent textComponent)
  6. isEmpty(JTextComponent component)
  7. isJavaContext(final JTextComponent component, final int offset, final boolean allowInStrings)
  8. isNonWhitespaceBetween(JTextComponent editor, int iStart, int iEnd)
  9. loadFileToPane(String fname, JTextComponent pane)