How to clear a JList correctly.
Hello,
I haven't found yet how to clear a JList whitout raising an exception.
I have defined a JList, that I initialize with a Vector. For example :
JList mylist =new JList();
Vector v =new Vector(5);
for (init i = 0; i<5; i++ ) v.add("Line " + i);
mylist.setListData(v);
.
When the user needs to erase all lines, he has to click on a JButton. In the actionPerformed method, I'm doing the following
Vector v =new Vector();
mylist.setListData(v);
It works, but I got an ArrayOutBoundException. I tried many other things such as
v.clear();
mylist.setListData(v);
but I got the same exception. So I was obliged to embed my instructions in a
try-catch block:
try
{
Vector v =new Vector();
mylist.setListData(v);
}
catch (Exception ex){}
In fact , I do not like what I did ,and I'm pretty sure it exists a much better way .
Thanks in advance for any suggestion
Gege

