Jlist validate

Hi friends

I am trying to transfer the data between multiple JList.

this is what my code looks like

initialization

int selectedIndex[] = null;

DefaultListModel dlmAddressAll;

JList jltAddressAll

--

if(event.getSource() == sbtnDeselectCC) {

selectedIndex = jltAddressCC.getSelectedIndices();

for(int i = 0; i < selectedIndex.length ; i++ ) {

dlmAddressAll.addElement(dlmAddressCC.get(selectedIndex));

}

jltAddressCC.validate();

for(int i = 0 ; i < selectedIndex.length ; i++) {

dlmAddressCC.remove(selectedIndex);

}

i am using JDK 1.6

i am facing some problems regarding this function

ListSelectionModel is MULTIPLE_INTERVAL_SELECTION.

1.When i select all the rows from the list and then transfer to another List, they get added in target list but while removing from the original list only half of the rows are removed.

2.Many times i face ArrayIndexOutOfBound exception when while removing the elements equal to size of list.

Also after we add any element to a list model we perform validate method on list . But is it right to call that method on the list from which elements are removed.

If any one know the solution .

Thanks

--Sunny Jain

null

[1334 byte] By [sunnyjaina] at [2007-11-27 5:51:13]
# 1
check this URL http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
AnanSmritia at 2007-7-12 15:39:59 > top of Java-index,Desktop,Core GUI APIs...
# 2

1. Use [url http://forum.java.sun.com/help.jspa?sec=formatting]code formatting[/url] when posting code.

2. No need to call validate on any of the lists.

3. This can't be your code because there's no remove int[] function in DefaultListModel.

4. You probably meant dlmAddressCC.remove(selectedIndex[i]);

But you have to reverse the loop and remove the last index first, because if you remove the first index first all the indexes that follow in the list are changed, and the list size is decreased by 1, which may cause an ArrayIndexOutOfBound exception.

for(int i = selectedIndex.length-1; i >=0 ; i--) {

dlmAddressCC.remove(selectedIndex[i]);

}

Rodney_McKaya at 2007-7-12 15:39:59 > top of Java-index,Desktop,Core GUI APIs...