aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Browse picture in JScrollpane !!!" Watch "Browse picture in JScrollpane !!!" New topic
Author

Browse picture in JScrollpane !!!

Sim Cray
Greenhorn

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();
label.setLayout(null);
label.setIcon(pic);
JScrollPane jsp = new JScrollPane(label);
getContentPane().add(jsp);
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
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: http://aspose.com/file-tools
 
subject: Browse picture in JScrollpane !!!