Reputation: 273
I'm trying to manipulate with 2 Jlists and using buttons to pass the items from one list to another, like this:
So far I have tried with this chunk of code:
if(jliIz.getSelectedIndex() > 0) {
jliIzKoncno.add(jliIz.getComponent(jliIz.getSelectedIndex()));
}
//jliIz is JList is the first JList
//jliIzKoncno is JList where I want to add elements
But it throws a java.lang.ArrayIndexOutOfBoundsException: No such child: 1 // or any other index
when I try to execute the code above.
Also, how will I delete the items from the first (jliIz
) list after I add the item to the other list (jliIzKoncno)
Thanks a lot!
Upvotes: 0
Views: 131
Reputation: 46871
Call JList#setListData() again after clearing the list.
Please have a look at How to clear a JList in Java?
Upvotes: 0
Reputation: 1045
Why not to use some ListModel
eg. (http://docs.oracle.com/javase/7/docs/api/javax/swing/DefaultListModel.html) class to manipulate JList
?
Upvotes: 1