J
jimgardener
I have an ImagePanel subclassed from JPanel ,where I can set an image
class ImagePanel extends JPanel{
private BufferedImage bi;
public ImagePanel(){
super();
}
public void setImage(String imagefilename) throws IOException{
bi = ImageIO.read(new File(imagefilename));
this.setPreferredSize(new Dimension(bi.getWidth(),bi.getHeight()));
this.revalidate();
this.repaint();
}
@Override
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0,0,getWidth(),getHeight());
g.drawImage(bi,0,0,null);
}
}
I can set the image by giving an image filename.But I wish to clear
the previous image from the panel,thus showing a blank image panel,if
a user supplies an invalid image name.
How can I do this?Can someone please tell me?
thanks
jim
class ImagePanel extends JPanel{
private BufferedImage bi;
public ImagePanel(){
super();
}
public void setImage(String imagefilename) throws IOException{
bi = ImageIO.read(new File(imagefilename));
this.setPreferredSize(new Dimension(bi.getWidth(),bi.getHeight()));
this.revalidate();
this.repaint();
}
@Override
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0,0,getWidth(),getHeight());
g.drawImage(bi,0,0,null);
}
}
I can set the image by giving an image filename.But I wish to clear
the previous image from the panel,thus showing a blank image panel,if
a user supplies an invalid image name.
How can I do this?Can someone please tell me?
thanks
jim