Display values inside a JList -
- by sharon Hwk
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 ?