Solved

JScrollPane Scrolling Problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

863 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

21 Experts available now in Live!

Get 1:1 Help Now