문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top