• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Autoscrolling for marquee selection

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic