• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Scroll an Image

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Rob Camick
Ranch Hand
Posts: 2701
10
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:

I didn't even know of this. Thanks Rob! Learnt something new today.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!