Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Zoom in and out

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Zoom in and out

    Hi,

    I am working on a Java project, based on calibrations, I generate a graph for which I need to implement the feature Zoom in and out. I must make it enlarge and small when the mouse scroll / wheel is moved up and down, or provide an option to enlarge when it is doubled clicked (like how it appears in windows image viewer)

    Is this feasible to do. Could someone share their thoughts on this, so that I can get started.

    Thanks,
    K


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Zoom in and out

    Yes you can.

    There are a few different options. The solution I usually prefer is to add your pane into a JScrollPane. In order to allow you to make a custom binding for middle mouse wheel scrolling, you will probably want to disable scrolling with the mouse wheel (see the setWheelScrollingEnabled(boolean) method).

    Then you just need to add a mouse listener and implement zooming/panning in here. To actually zoom, just change the preferred size for your graph component (see setPreferedSize(Dimension). Note that this method only works if your graph component takes into account the size of the component while painting.