Re: Removing an item from a Jlist



On Feb 28, 3:49 pm, christopher_bo...@xxxxxxxxxxx wrote:
On 28 Feb, 14:47, TheBigPJ <TheBi...@xxxxxxxxx> wrote:

I think this link will satisfy your needs and maybe more.

http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

Hi all. Thanks for the replies. I have had a look at the website
mentioned above by TheBigPJ and have entered the following the code
into my program:
int index = lstComputerExceptions.getSelectedIndex();
lstComputerExceptions.remove(index);

lstComputerExceptions.setSelectedIndex(index);
lstComputerExceptions.ensureIndexIsVisible(index);
}

However when I run it always comes up with the following error
message:
ception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
<snip>

I suspect that the error refers to line of code
= lstComputerExceptions.setSelectedIndex(index);
If you look at the line immediately preceding that one you might see
what may be causing the error...
.