This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Autoscrolling for marquee selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Autoscrolling for marquee selection" Watch "Autoscrolling for marquee selection" New topic
Author

Autoscrolling for marquee selection

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
I jave a JPanel within a JScrollPane; that JPanel contains numerous image thumbnails. Currently, I allow users to drag a marquee box over various images, thus "selecting" those image (nothing out of the ordinary there, much like any similar program would do).

More often than not, there are more image thumbnails below the fold, where the user would need to scroll down to get to. I realized that if the user attempt to drag the marquee below the fold, the JPanel should autoscroll, allowing the marquee to select the images down below.

So, has anyone implemented something like this? I know there is the Autoscroll interface, but that is designed only to work with DnD. If my JPanel isn't associated with a DropTargetListener, and more importantly if I'm not actually dragging a DragSource through it, the Autoscroll mechanism won't work. I'm curious if the API offers something similar to those of us who aren't doing Drag & Drop, but merely Drag.


Dave Taubler<br />Specializing in <a href="http://taubler.com/articles/" target="_blank" rel="nofollow">Java and Web Development</a>
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
Cool, a homespun answer! I was figuring that would be the route to take, but I thought I'd check to see if I was missing something in the API.

Anyway, thanks, Craig; I will give that a whirl.
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
That got me on the right track. In my case, I had to make a second Rectangle r, based on the marquee's position, to scrollRectToVisible(r). That's because my marquee could grow in size to be larger than the scrollable viewport.

The only trick now is to make it autoscroll even if the user isn't currently moving their mouse; right now, the user needs to not only drag the cursor below the fold, but also wiggle it around a bit to fire off those mouse drag events. But hopefully I can spawn off a Thread to handle that.

Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Autoscrolling for marquee selection