Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JScrollPane Scrolling Problem

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 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

721 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