JList: how a set a "name" and "value" for a element
my JList
DefaultListModel listMBuddy;
JList listBuddy;
listMBuddy =new DefaultListModel();
listBuddy =new JList(listMBuddy);
listMBuddy.insertElementAt("buddy name 1", listMBuddy.size());
listMBuddy.insertElementAt("buddy name 2", listMBuddy.size());
listMBuddy.insertElementAt("buddy name 3", listMBuddy.size());
a string "buddy name 1" will be show in JList, it is like a name of element.
how i set value for "buddy name 1"? like html
<select>
<option value="5">buddy name 1</option>
<option value="7">buddy name 2</option>
<option value="2">buddy name 3</option>
</select>
thanks
[870 byte] By [
NhTina] at [2007-11-26 17:14:36]

You have to write your own renderer.
example:
public class MyListsRenderer extends JPanel implements ListCellRenderer {
JTextArea t;
private LinkedHashMap<Integer, String> departmentsList;
private LinkedHashMap<Integer, Boolean> checkedList;
public MyListsRenderer(int tabSize) {
t = new JTextArea();
t.setTabSize(tabSize);
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
Integer id = (Integer) value;
// you need to create class that get an id (value) and return name
//this is my example:
String name = Contacts.getInstance().getContacts().get(
(Integer) value);
t.setText(name);//this is the text in the list row
add(t);
return this;
}
}