users
[Top] [All Lists]

RE: [cinjug-users] Swing JScrollPane Question

To: <users@xxxxxxxxxx>
Subject: RE: [cinjug-users] Swing JScrollPane Question
From: "Brian Engel" <Brian.Engel@xxxxxxxxxxxx>
Date: Thu, 11 Nov 2004 15:30:17 -0500
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Thread-index: AcTIIzRTFPO/G0viSvicwM8VrtyqOwACdAkQ
Thread-topic: [cinjug-users] Swing JScrollPane Question
Yes, I encountered the same problem... I got part (or all) of this code somewhere on the internet. Use this for your JTree...
 
 
import java.awt.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
 
public class AutoScrollingJTree extends JTree implements Autoscroll {
  private int margin = 12;
 
  public AutoScrollingJTree()
  {
    super();
  }
 
  public AutoScrollingJTree(DefaultMutableTreeNode dmtn)
  {
    super(dmtn);
  }
// Ok, we’ve been told to scroll because the mouse cursor is in our
// scroll zone.
  public void autoscroll(Point p)
  {
 
    int realrow = getRowForLocation(p.x, p.y);
    Rectangle outer = getBounds();
    realrow = (p.y + outer.y <= margin ?
 
    realrow < 1 ? 0 : realrow - 1 :
    realrow < getRowCount() - 1 ? realrow + 1 : realrow);
    scrollRowToVisible(realrow);
  }
 
  // Calculate the insets for the *JTREE*, not the viewport
  // the tree is in. This makes it a bit messy.
  public Insets getAutoscrollInsets()
  {
    Rectangle outer = getBounds();
    Rectangle inner = getParent().getBounds();
    return new Insets(
    inner.y - outer.y + margin, inner.x - outer.x + margin,
    outer.height - inner.height - inner.y + outer.y + margin,
    outer.width - inner.width - inner.x + outer.x + margin);
  }
 
}
 
 
 
 


From: Connerth, David [mailto:DCONNERT@xxxxxxxxxxxxxxxx]
Sent: Thursday, November 11, 2004 2:18 PM
To: users@xxxxxxxxxx
Subject: [cinjug-users] Swing JScrollPane Question

Does anyone know how to make a Swing JScrollPane autoscroll during a drag?  For example, if I have a JTree in a JScrollPane, and the tree has nodes not visible, I should be able to “drag and drop” onto one of the non-visible nodes by autoscrolling during the drag and drop operation.  Any ideas?  I have tried JScrollPane.SetAutoScrolls(true), but that does not seem to work.

 

Thanks,

 

David L. Connerth

 

Director, Digital Collections Development

Gannett Media Technologies International

 

513.587.2941 Phone 513.241.7219 Fax

dconnerth@xxxxxxxxxxxxxxxx

 

<Prev in Thread] Current Thread [Next in Thread>
  • RE: [cinjug-users] Swing JScrollPane Question, Brian Engel <=