Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic