Java JScrollPane Scroll scrollComponentTo(JComponent c, Rectangle r)

Here you can find the source of scrollComponentTo(JComponent c, Rectangle r)

Description

Scroll a component contained in a JScrollPane to its end

License

Open Source License

Declaration

public static void scrollComponentTo(JComponent c, Rectangle r) 

Method Source Code


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

import java.awt.Rectangle;

import javax.swing.JComponent;

public class Main {
    /**/*  w  w  w  . ja v  a 2s.  co m*/
     * 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. scrollComponentToEnd(JComponent c)
  2. scrolleable(final JComponent comp)
  3. scrollH(JComponent content)
  4. scrollRectLater(final JComponent comp, final Rectangle r)