Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

BufferedImage to JScrollPane

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I have an app that I am writing that loads and image, using ImageIcon, converts this to a BufferedImage and then filters it (resize, bright etc)

This is all working within a JFrame just using the below to hold the image amoungst the control buttons



thisImage is a buffered image.

Now what I want to do is add the image into a JScrollPane. I have tried adding the image first to a panel and then wrap this with the JScrollPane, then add the scrollPane to my master JFrame.

But have no joy in getting it working. It just comes up with a blank JFrame??

Am I approaching this in the wrong way. What would be the best technique to do this sort of thing?

Thanks for taking the time to read.

cheers
Martin
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

I just completed a very similar challange.

I put the ImageIcon on a JLabel and then put the label in the scrollpane. Give that a try and if you have no luck then post some code.

Cheers,
Rachel
 
Martin Thorpe
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rachael. I tried that with ImageIcon. but what I am dealing here with is a BufferedImage which I don't think I can assign to a JLabel, unless I am wrong.

The reason I am using a BufferedImage is to take advantage of the BufferedImageOp and AffineTransform classes/methods.

I will look further at getting a BufferedImage inot the JLabel.

cheers
Martin
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there.

Sorry for reading your post wrong! I thought you wanted to display the ImageIcon.

(Aside I found that I could make the BufferedImage into an ImageIcon but then everytime I changed the BufferedImage I kept having to reflect the change in the ImageIcon.)

Then I found the better solution...

I had to create my own component that extends JPanel and I use Graphics2D to draw the image onto the component using drawRenderedImage(...).

The other reason that I went with making my own component was that when including any component in a JScrollPane, I found that the pane expands the component it holds. So on my custom component I could control the getPreferredSize a little better.

That is the broader strokes of what I did.

Cheers,
Rachel
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello :-)

I am really interested in this thread as I have run into similar problems

I am trying to get a map of hexes drawn onto a BufferedImage 500 x 500 pixels in size, and then display this within a JScrollPane, so that this map can be scrolled by the user.

My problem is that my current attempt does not produce an image in the JScrollPane that scrolls - it is as if the BufferedImage is clipped to the size of the JPanel.

Please see code below and help me :-)

 
D R Wilkinson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I may have found what I need on the sun website, so I am posting the url for anyone else who needs this sort of functionality - ScrollDemo2

ScrollDemo2 Source

ScrollDemo2 WebStart

Darren
[ November 14, 2004: Message edited by: D R Wilkinson ]
reply
    Bookmark Topic Watch Topic
  • New Topic