File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Browse picture in JScrollpane !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Browse picture in JScrollpane !!!" Watch "Browse picture in JScrollpane !!!" New topic

Browse picture in JScrollpane !!!

Sim Cray

Joined: Apr 04, 2005
Posts: 7
I make an JLabel
and setIcon("back.gif") for it
then I new an JScrollPane with the label
and add ScrollPane in JFrame.

when the back.gif is 1050*722 size(105KB), I can browse it well in ScrollPane. Then I change to another pic of 2000*582(214KB), well yet.
But when I change to a pic of 2400*698(316KB), I can't see the pic,
only a gray panel without any scrollbar! I want to know why? Any suggestion ? For god's sake, help me, thanks a lot!

import java.awt.*;
import javax.swing.*;

public class MapTest extends JFrame {
public MapTest()
ImageIcon pic = new ImageIcon("back.gif");
JLabel label = new JLabel();
JScrollPane jsp = new JScrollPane(label);
setSize(600, 400);
public static void main(String[] args)
new MapTest();
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
If you simply change the file name inside the ImageIcon constructor and run the app again and the new image does not show then I would suspect a file/path typo or the possibility that either the image file has not been properly saved to your hard drive or that it has corrupted data. On the other hand, if you are changing the imageIcon in the JLabel during runtime then you will want to tell the gui that you have altered the size of the component (JLabel with the new, larger icon) and ask it to re–do its layout. Calling either 'validate' or 'revalidate' on the JScrollPane may be enough to do this.
I agree. Here's the link:
subject: Browse picture in JScrollpane !!!
It's not a secret anymore!