We help IT Professionals succeed at work.

Swing JViewport and zooming

Sumir
Sumir asked
on
I am using a JScrollPane to display some graphical objects for my application.  I'm trying to allow the ability to zoom in and out.  I decided to use the JViewport class but I can't seem to figure out which methods to use, or how to do it.  The web had nothing on this topic.  I bought an advanced Swing book, but it hasn't arrived yet.  HELPPPPP!!!!!

Has anyone done this before?  Any help would be greatly appreciated
Comment
Watch Question

Commented:
I was asking a similar question just the other day:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20169876

objects suggested using one of the drawImage() methods in the Graphics class to scale the image.

Author

Commented:
Thanks yongsing, but I really do not want to increase the size of each object on my panel when I am trying to zoom.  It is like looking at a cell under a microscope.  When you want to zoom in you don't expand the cell, you expand your view of the cell.  

That is why I want to use the JViewport class, but I can't seem to get it to work.  Has anyone used it successfully?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
I don't think JViewport is designed for zooming.
It merely provides a window onto a larger canvas, it provides no support for zooming in or out of that canvas.

To implement what you want you will need to develop your own class.

Author

Commented:
objects,

Your comment is very insightful.  No wonder I couldn't get it to do zooming.  So do you suggest any way I can do the zooming?
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
You could build a component that displays your graphical objects at your requested zoom level (and allows u to change this zoom level).
You could then wrap this in a scroll pane to handle panning.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
Hi Sumir,
You've requested to delete this question, but its status has remained as 'Pending Delete' because one or more comments have been added.  Normally, the only way to fully delete such a Question is to post a message to Community Support and ask for assistance.

EE is making a one-time database sweep to purge the Pending Delete Questions automatically.  During this sweep:

    Sumir -- To allow the deletion to proceed:  Do nothing.
    EXPERTS -- Please DON'T POST a comment except to contest this deletion.

In the future, please refer to http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp#8 for instruction on deleting questions.

DanRollins -- EE database cleanup volunteer
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Hmm, I explained why the JViewport was not suitable and offered an alternative.
Thank you, finalized today by Moondancer - EE Moderator