Remove images from JPanel

Hi,

I have a JPanel called imagePanel and a JTree and every time a node is selected in the tree, a set of images are gonna be displayed on the imagePanel

with the loop below. But the next time a node is selected the images that were added via the loop the first time, has to be removed. What code can I use to

empty the imagePanel everytime, before the for-loop runs?

//Some code here to empty the imagePanel so it begins from scratch

for(int index=0; index < imageNames.size(); index++)

{

ImageIcon newImage = createImageIcon("images/" +

(String)imageNames.elementAt(index));

imagePanel.add(new JLabel(newImage));

pictureLabel.setText(null);

}

[963 byte] By [nd00jana] at [2007-10-1 13:53:03]
# 1
And you've checked the JPanel API?
es5f2000a at 2007-7-10 17:05:33 > top of Java-index,Security,Cryptography...
# 2
imagePanel.removeAll();
74philipa at 2007-7-10 17:05:33 > top of Java-index,Security,Cryptography...
# 3
> imagePanel.removeAll();Thanks!
nd00jana at 2007-7-10 17:05:33 > top of Java-index,Security,Cryptography...
# 4
Hi ,try thisjlabel.setIcon( null ) ;
LittleDanya at 2007-7-10 17:05:33 > top of Java-index,Security,Cryptography...