Solved

JScrollPane Scrolling Problem

Posted on 2006-10-22
2
227 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now