Display values inside a JList -
Posted
by
sharon Hwk
on Stack Overflow
See other posts from Stack Overflow
or by sharon Hwk
Published on 2012-12-10T10:45:07Z
Indexed on
2012/12/10
11:05 UTC
Read the original article
Hit count: 281
I have a method that returns a HashMap
, and is defined as follows;
public HashMap<Integer, Animal> allAnimal(){
return returnsAHashMap;
}
Animal
will have the following values in its class:
public Animal{
int animalID;
String animalName;
// i have declared getters/setters
}
I have a GUI screen which has a JList
and it's defined as:
l = new JList();
l.setModel(new AbstractListModel() {
String[] v = new String[] {"animal id 1", "2", "3"};
public int getSize() {
return v.length;
}
public Object getElementAt(int index) {
return v[index];
}
});
What I want to do is to display the AnimalID's in the JList. I need to find a way to call the allAnimal()
method and display all its Animal Id's in the JList
. How can i do this ?
© Stack Overflow or respective owner