URGENT help. Refreshing imageicon in JLabel.

privatevoid friendList_valueChanged(ListSelectionEvent e){

//lblPersonal.setBounds(new Rectangle(20, 305, 75, 85));

//ImageIcon personalImage;

//personalImage = new ImageIcon("classes/project1/yuanlong.jpg");

//personalImage = (friendList.getSelectedIndex());

//lblPersonal = new JLabel(personalImage);

//friendsPanel.add(lblPersonal, null);

//This event will change the infromation of the bottom panel

//1) Compare the selected name to the database? inorder to get the correct infromation

//2) After compare, create the object and print object infromation to the bottom panel

if (friendList.isSelectionEmpty() !=true){

friendsObj friXX;

friXX = (friendsObj)friendList.getSelectedValue();

taFriendProfile.setText(friXX.toStringALL());

updateProfilePic(friXX);

}

}

publicvoid updateProfilePic (friendsObj friXX2){

lblPersonal2.repaint();

lblPersonal2.setBounds(new Rectangle(8, 23, 75 , 85));

lblPersonal2 = friXX2.getPathIcon();

profilePanel.add(lblPersonal2,null);

}

When I click on a name in the JList, there is a panel that is suppose to show the different pictures of the person that is selected.

However, when I click on a name in the JList, the picture shows, but when I click on ANOTHER name, the picture remains as the first picture displayed. I have tried several methods but is still unable to solve it. I would really appreciate ANY help on this. Thank you!

EDIT: If it is required, I'm using JDeveloper.

Message was edited by:

rhexis

I have edited my code a little after reading through the forums abit.

if (friendList.isSelectionEmpty() !=true){

friendsObj friXX;

friXX = (friendsObj)friendList.getSelectedValue();

taFriendProfile.setText(friXX.toStringALL());

String name;

name = (String)friendList.getSelectedValue();

lblPersonal2.setBounds(new Rectangle(8, 23, 75 , 85));

//String pictureDirectory = new String("classes/project1/"+name+".jpg");

String directory =new String(friXX.getPicture(name));

lblPersonal2.setIcon(new ImageIcon(directory));

profilePanel.add(lblPersonal2,null);

}

}

public String getPicture(String name){

//JLabel lblPicture = new JLabel();

//lblPicture.setIcon(new ImageIcon("classes/project1/Alex"+name+".jpg"));

String pictureDirectory =new String("classes/project1/" +name+".jpg");

return pictureDirectory;

}

But I;m having a class cast exception on

name = (String)friendList.getSelectedValue();

when I click on a name in the JList. I have tried Convert.ToString() but it doesn't exist. Any suggestions please?

Message was edited by:

rhexis

[4104 byte] By [rhexisa] at [2007-11-27 3:55:02]
# 1
how about the validate method ?
AnanSmritia at 2007-7-12 8:59:11 > top of Java-index,Desktop,Core GUI APIs...