hganywhere
Programmer
I would like to use a JList to display employee information and allow add/delete operations on this JList.
I am having a problem when adding/removing a record from the JList, the model is being updated but the JList goes blank.
I do not use Arrays, Vectors etc to maintain my model. My model is an ArrayList of EmployeeVO's.
An EmployeeVO class will have fields such as :
EmpId
EmpFirstName
EmpLastName
etc.
The EmployeeVO also has a toString() method that allows for displaying of the EmployeeVO inside the JList.
The Model is defined as :
//
// Our Employee Model
//
class EmployeeListModel2 extends AbstractListModel
{
private EmployeeListCollection collection=null;
EmployeeListModel2(EmployeeListCollection c)
{
this.collection=c;
}
public int getSize()
{
return collection.getEmployeeCount();
}
public Object getElementAt(int index)
{
return collection.getDisplayItem(index);
}
public void addElement(Object o)
{
int index=collection.getEmployeeCount();
collection.addElement(o);
fireIntervalAdded(this,index,index);
}
public ArrayList getElements()
{
return collection.getEmployeeList();
}
public void addListDataListener(ListDataListener l)
{
}
public void removeListDataListener(ListDataListener l)
{
}
}
The EmployeeListCollection class is defined as
//
// Data Structure to hold employee list
//
class EmployeeListCollection
{
private ArrayList employeeList=null;
EmployeeListCollection(ArrayList l)
{
this.employeeList=l;
}
public void addElement(Object o)
{
System.out.println("EmployeeListCollection.addElement - "+o);
employeeList.add(o);
}
public int getEmployeeCount()
{
return employeeList.size();
}
public ArrayList getEmployeeList()
{
return employeeList;
}
public Object getDisplayItem(int index)
{
return (EmployeeVO)employeeList.get(index);
}
}
The code to add an item is defined as :
public void __add(EmployeeVO vo)
{
int size=model.getSize();
model.addElement(vo);
}
Does anyone have any ideas ?
P.s, I do not get a problem if I use DefaultListModel or use a model that is based on an Array or Vector.
TIA
I am having a problem when adding/removing a record from the JList, the model is being updated but the JList goes blank.
I do not use Arrays, Vectors etc to maintain my model. My model is an ArrayList of EmployeeVO's.
An EmployeeVO class will have fields such as :
EmpId
EmpFirstName
EmpLastName
etc.
The EmployeeVO also has a toString() method that allows for displaying of the EmployeeVO inside the JList.
The Model is defined as :
//
// Our Employee Model
//
class EmployeeListModel2 extends AbstractListModel
{
private EmployeeListCollection collection=null;
EmployeeListModel2(EmployeeListCollection c)
{
this.collection=c;
}
public int getSize()
{
return collection.getEmployeeCount();
}
public Object getElementAt(int index)
{
return collection.getDisplayItem(index);
}
public void addElement(Object o)
{
int index=collection.getEmployeeCount();
collection.addElement(o);
fireIntervalAdded(this,index,index);
}
public ArrayList getElements()
{
return collection.getEmployeeList();
}
public void addListDataListener(ListDataListener l)
{
}
public void removeListDataListener(ListDataListener l)
{
}
}
The EmployeeListCollection class is defined as
//
// Data Structure to hold employee list
//
class EmployeeListCollection
{
private ArrayList employeeList=null;
EmployeeListCollection(ArrayList l)
{
this.employeeList=l;
}
public void addElement(Object o)
{
System.out.println("EmployeeListCollection.addElement - "+o);
employeeList.add(o);
}
public int getEmployeeCount()
{
return employeeList.size();
}
public ArrayList getEmployeeList()
{
return employeeList;
}
public Object getDisplayItem(int index)
{
return (EmployeeVO)employeeList.get(index);
}
}
The code to add an item is defined as :
public void __add(EmployeeVO vo)
{
int size=model.getSize();
model.addElement(vo);
}
Does anyone have any ideas ?
P.s, I do not get a problem if I use DefaultListModel or use a model that is based on an Array or Vector.
TIA