• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

How to Scroll an Image

 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the scenario:
I have a java swing application.
1. The human user of my application asks it to fire up a scanner which
scans a paper document. The document is a filled in form.
2. The application then displays the scanned image to the human user.
The image is displayed in a JScrollPane since it may be larger than
the scroll pane.
3. The human user needs to locate a certain item in the form, for example
a social security number, and enter it into a field in a data entry
screen. Note that the image and the field appear on the same screen.

Of-course the social security number always appears in the same location
in the image.
Also the image needs to be the appropriate magnification and resolution
to allow the human user to easily read and understand the item he is
searching for in the image.

I would like someone to point me in the right direction as to the best
way to present the scanned image to the user such that he immediately
sees the item he requires and can enter it into the data entry field.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avi Abrami wrote:
I would like someone to point me in the right direction as to the best
way to present the scanned image to the user such that he immediately
sees the item he requires and can enter it into the data entry field.



JComponent#scrollRectToVisible(Rectangle rectangle);

Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.



If you know the image size, resolution, location of where the appropriate data in the image is located, you can compute the rectangle (perimeter of the data) and programatically scroll your image to display the data
 
Rancher
Posts: 3287
30
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The scrollRectToVisible(...) method will only scroll when the Rectangle is not currently visible in the viewport. So you need to manipulate the width/height to make your Rectangle large enough to force a scroll.

I find the following easier to use since you only need to worry about the location you want to scroll to:



then the viewport will scroll whether the location is currently in the viewport or not.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:


I didn't even know of this. Thanks Rob! Learnt something new today.
 
today's feeble attempt to support the empire
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic