Solved

JScrollPane Scrolling Problem

Posted on 2006-10-22
2
231 Views
Last Modified: 2010-08-05
Hi,

I have a very frustrating problem that i have been working on for several hours with no success. I basically want a panel on which i draw an image (using graphics.drawimage). I want to be able to zoom into the image (by making the panel bigger and drawing a bigger image on it), and when the image panel gets bigger than the window, scroll bars appear.

I have got this partially working, however when the panel is larger than the window and i try increasing the size even more, the scrollbars do not adjust to the new size. And also, when i reduce the size from very large (but still bigger than the window) the scroll bars do not change.

Im sorry if i havent explained myself very well!

Here's some sample code:

            CONSTUCTOR:
            .....
            JPanel imagePane = new JPanel;
            imagePane.parent = this;
            previewScroller = new JScrollPane(imagePane);
            .....

When i try to resize the image i do this:

            INSIDE THE JPANEL [imagePane]:
            .....
            this.setPreferredSize(new Dimension(newWidth(), newHeight()));
            repaint(); // calls a overridden paint method that draws an image onto the panel
            parent.previewScroller.revalidate(); // SHOULD sort out the scrollbars!
            ......

I'm really not sure why its not working! I hope someone can shed some light on this. If you need any more information just let me know.

Thanks, Mike
0
Comment
Question by:Xavior2K3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
hoomanv earned 500 total points
ID: 17784339
revalidate() the imagePane after setPreferredSize
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17784669
What is the class extending of w.r.t .setPreferredSize.
You must avoid to set a size for the component that you got a viewport of.
If the image grows, its component must grow to enclose it.
Apply:
        .pack();
on it.

;JOOP!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question