jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes BufferedImage to JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BufferedImage to JScrollPane" Watch "BufferedImage to JScrollPane" New topic
Author

BufferedImage to JScrollPane

Martin Thorpe
Ranch Hand

Joined: May 25, 2004
Posts: 45
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
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
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

Joined: May 25, 2004
Posts: 45
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

Joined: May 18, 2004
Posts: 434
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
D R Wilkinson
Ranch Hand

Joined: Oct 29, 2004
Posts: 51
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

Joined: Oct 29, 2004
Posts: 51
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: BufferedImage to JScrollPane
 
Similar Threads
problem relating to jpanel background image
GUI Scrollbar and file browser
Drawing an image
Save JScrollPane as Image
Getting scrollbars to scroll