Question

I'm trying to manipulate with 2 Jlists and using buttons to pass the items from one list to another, like this:

enter image description here

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!

Was it helpful?

Solution

Why not to use some ListModel eg. (http://docs.oracle.com/javase/7/docs/api/javax/swing/DefaultListModel.html) class to manipulate JList?

OTHER TIPS

Call JList#setListData() again after clearing the list.

Please have a look at How to clear a JList in Java?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top