• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Browse picture in JScrollpane !!!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic