Re: Removing Item From JList - getSelectedIndex problem
by Lew <lew@[EMAIL PROTECTED]
>
Apr 10, 2008 at 07:53 AM
CBO wrote:
>> I am currently working on a JList that populates data into a JList
>> from a CSV file. I have a button that is supposed to get the Selected
>> index and then delete that item from the JList. Below is the code that
>> I am using:
>>
>> int index = lstComputerExceptions.getSelectedIndex();
>> System.out.println("index is: " + index);
>> model.remove(0);
>>
>> int size = model.getSize();
>>
>> if (size == 0) { //Nobody's left, disable firing.
>> btnDelete.setEnabled(false);
>>
>> } else { //Select an index.
>> if (index == model.getSize()) {
>> //removed item in last position
>> index--;
>> }
>>
>> lstComputerExceptions.setSelectedIndex(index);
>> lstComputerExceptions.ensureIndexIsVisible(index);
>> }
>>
>> I have printed out what index is and no matter what item I have in the
>> Jlist I have selected it will always print out
>> -1. Therefore keeps on causing my program to crash and not delete the
>> item out of the Jlist.
>>
>> Any help in this matter would be highly appreicated.
> This issue has been resolved
Don't keep us in suspense! What was the answer?
--
Lew