Java JScrollPane Scroll scrollComponentToEnd(JComponent c)

Here you can find the source of scrollComponentToEnd(JComponent c)

Description

Scroll a component contained in a JScrollPane to its end

License

Open Source License

Declaration

public static void scrollComponentToEnd(JComponent c) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Rectangle;

import javax.swing.JComponent;

public class Main {
    /**/*from   w  w  w  .j a v a2 s  . c o  m*/
     * Scroll a component contained in a JScrollPane to its end
     */
    public static void scrollComponentToEnd(JComponent c) {
        Rectangle r = c.getBounds();
        scrollComponentTo(c, new Rectangle(0, r.height - 2, r.width, 2));
    }

    /**
     * Scroll a component contained in a JScrollPane to its end
     */
    public static void scrollComponentTo(JComponent c, Rectangle r) {
        int extraHeight = 40; // 2*r.height ;
        Rectangle rr = new Rectangle(r.x, r.y - extraHeight, r.width, 2 * extraHeight + r.height);
        Rectangle rrr = rr.intersection(c.getBounds());
        //System.out.println( "rr=" + rr + ", rrr=" + rrr + ", bounds=" + c.getBounds() ) ;
        if (rrr.height > 0)
            c.scrollRectToVisible(rrr);
    }
}

Related

  1. scrollComponentTo(JComponent c, Rectangle r)
  2. scrolleable(final JComponent comp)
  3. scrollH(JComponent content)
  4. scrollRectLater(final JComponent comp, final Rectangle r)
  5. scrollRectToVisible(Component component, Rectangle aRect)