Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JScrollPane Scrolling Problem

Posted on 2006-10-22
2
Medium Priority
?
236 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 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…
Suggested Courses

927 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