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

[1394 byte] By [martinelligegea] at [2007-10-2 19:13:41]
# 1
This link has answer... http://forum.java.sun.com/thread.jspa?threadID=718897&messageID=4149627
Happy2b1a at 2007-7-13 20:54:59 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks a lot.
martinelligegea at 2007-7-13 20:54:59 > top of Java-index,Desktop,Core GUI APIs...