This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes How to paint a java.awt.Image in a JScollPane? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to paint a java.awt.Image in a JScollPane?" Watch "How to paint a java.awt.Image in a JScollPane?" New topic
Author

How to paint a java.awt.Image in a JScollPane?

John Wells
Greenhorn

Joined: Apr 10, 2003
Posts: 7
Guys,
I'm trying to paint an image inside a JScrollPane. My app is essentially structured as:
JFrame
|
JDesktopPane
|
JInternalFrame
|
JScrollPane
|
JPanel
|
java.awt.Image
But when I try to paint the image in the JPanel's paint method, it doesn't seem to open a viewport around the whole image. The image is there, and the scroll bars are there (I force them to always be displayed), but the image is cropped and the scrollbars do not scroll across the entire image. In other words, it seems like the image is being painted, but the viewport is too small.
Can anyone offer any suggestions or pointers to good tutorials? I'm very new to working with images in Java.
Thanks very much for your help.
Sharon Zakhour
Author
Greenhorn

Joined: Apr 26, 2004
Posts: 10
We have an example in the tutorial that paints an image in a scroll pane.
In our example, the ScrollablePicture class is a subclass of label. You
can see it here:
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
Sharon Zakhour
John Wells
Greenhorn

Joined: Apr 10, 2003
Posts: 7
Ah, ok...I saw that tutorial, but because it uses an ImageIcon, I assumed that this wasn't a valid class to use for regular images (i.e., not "icons").
So is this not the case? Is ImageIcon the defacto image class in Swing, for all sizes?
Thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to paint a java.awt.Image in a JScollPane?