Hide value in List
How can I store a value and a hidden id (or something) for each row in a List
(java.awt)? I want to be able to click the list and use the hidden value,
pretty much like you use the itemData property on a listbox in Visual Basic.
Or can this be done easily with another object ?
Re: Hide value in List
javax.swing.JList is much better than java.awt.List for doing what you want.
Any object, not just strings, can be added to a JList. The objects you add
can house the id as well as the display text for each of your list items
public class MyListItem
private int id;
private String text;
public MyListItem(int id, String text)
this.id = id;
this.text = text;
public int getId()
* displayed in list
public String toString()
// creating the JList with MyListItem objects
javax.swing.DefaultListModel model = new javax.swing.DefaultModel();
model.add(new MyListItem(1, "Help"));
model.add(new MyListItem(2, "Me"));
javax.swing.JList list = new javax.swing.JList(model);
// accessing the selected item's id
MyListItem item = (MyListItem)list.getSelectedItem();
int id = item.getId();
"Pelle" <firstname.lastname@example.org> wrote in message news:email@example.com...
> How can I store a value and a hidden id (or something) for each row in a
> (java.awt)? I want to be able to click the list and use the hidden value,
> pretty much like you use the itemData property on a listbox in Visual
> Or can this be done easily with another object ?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center