aspose file tools*
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
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Autoscrolling for marquee selection