aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes repainting issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "repainting issue" Watch "repainting issue" New topic
Author

repainting issue

shihab K Bava
Greenhorn

Joined: Oct 03, 2004
Posts: 12
I have a JLabel on a JScrollPane. I am trying to load images in to the label as icon. The file names of the images are selected by a file chooser. My issue is when I load the image first time it shows correctly. But when I am trying to load another image, the 2nd image is not displaying. But first image is displaying there. Could you please check the code below and tell me where should do modification?

------------------------ Code Part ---------------------------
String imgName = chooser.getSelectedFile().getPath();
System.out.println(imgName);

ImageIcon imgIcon = new ImageIcon(imgName);

JLabel imgLabel = new JLabel(imgIcon);

setTitle("BrowseImage - " + imgName);

imagePane = new JScrollPane();
//imagePane.removeAll();
imagePane.add(imgLabel);
imagePane.revalidate();
imagePane.setViewportView(imgLabel);

imgLabel.setHorizontalAlignment(JLabel.CENTER);
imgLabel.setVisible(true);

getContentPane().add(imagePane,BorderLayout.NORTH);
imagePane.setSize(screenWidth-200,screenHeight-200);
imagePane.setLocation(100,50);

imgLabel.revalidate();

getContentPane().repaint();

setVisible(true);

--------------------------------------------------------
Thanks in advance
Shihab KB
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

A JScrollPane can only have one child component. Try using a JPanel that is the child component, then add your labels to that JPanel.

Also, please Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I'm reading this as though you have a single label
and just want to show another image in that label.

if so, all you need is (after showing the original image)

String imgName = chooser.getSelectedFile().getPath();
originalLabel.setIcon(new ImageIcon(imgName));
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: repainting issue