aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JScrollPane doesn't work. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane doesn Watch "JScrollPane doesn New topic
Author

JScrollPane doesn't work.

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi there, I'm trying to get an image drawn from within a JPanels' paintComponent(Graphics g) method inside a JScrollPane.

The Drawer object (drawer) extends JPanel, and has size 800 by 800.
This has an image also 800 by 800.

The JFrame class is shown here:


But what happens is, I can only see top left corner of image, and there are no ScrollBars present to move the image around inside of the JScrollPane jsp object.

Can anyone help me?
Thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you seem to be mixing the way to size:
null - setSize(..)
layoutManager - setPreferredSize(..)

(changed Drawer() to a JPanel with border)
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
AMAZING, very fast too!!!

All I did was change drawer.setSize(...) to preferredSize(...)
And that worked

Don't know what the difference is, I'll look into it.

Thanks again!
T Eakins
Greenhorn

Joined: Feb 20, 2004
Posts: 9
For those who came across this (as I did), wanted to post a follow-on solution. The code above works because there is no layout manager, which is uncommon for larger projects. Here's the same block using a common layout manager, MigLayout (not using any of its bells and whistles), and the SwingX implementation of JXPanel. Note that JXPanel can be easily replaced with JPanel, just remove the additional lines that tell the panel not to recalculate its size dynamically, but to enforce the scrollable region.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane doesn't work.