Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: Removing It...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 15947 of 16566
Post > Topic >>

Re: Removing Item From JList - getSelectedIndex problem

by CBO <christopher_board@[EMAIL PROTECTED] > Apr 10, 2008 at 05:49 AM

On 10 Apr, 12:53, Lew <l...@[EMAIL PROTECTED]
> wrote:
> 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:
>
> >> =A0int index =3D lstComputerExceptions.getSelectedIndex();
> >> =A0 =A0 =A0 =A0 System.out.println("index is: " + index);
> >> =A0 =A0 =A0 =A0 model.remove(0);
>
> >> =A0 =A0 =A0 =A0 int size =3D model.getSize();
>
> >> =A0 =A0 =A0 =A0 if (size =3D=3D 0) { //Nobody's left, disable firing.
> >> =A0 =A0 =A0 =A0 =A0 =A0 btnDelete.setEnabled(false);
>
> >> =A0 =A0 =A0 =A0 } else { //Select an index.
> >> =A0 =A0 =A0 =A0 =A0 =A0 if (index =3D=3D model.getSize()) {
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //removed item in last position
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 index--;
> >> =A0 =A0 =A0 =A0 =A0 =A0 }
>
> >> =A0 =A0 =A0 =A0 =A0 =A0
lstComputerExceptions.setSelectedIndex(index);
> >> =A0 =A0 =A0 =A0 =A0 =A0
lstComputerExceptions.ensureIndexIsVisible(inde=
x);
> >> =A0 =A0 =A0 =A0 }
>
> >> 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! =A0 What was the answer?
>
> --
> Lew- Hide quoted text -
>
> - Show quoted text -

I had accidently initialized the JList model twice so it kept on
causing it to go wrong. Deleted it and now it works fine. I wasn't
that bright lol
 




 4 Posts in Topic:
Removing Item From JList - getSelectedIndex problem
CBO <christopher_board  2008-04-09 03:21:18 
Re: Removing Item From JList - getSelectedIndex problem
CBO <christopher_board  2008-04-10 01:39:36 
Re: Removing Item From JList - getSelectedIndex problem
Lew <lew@[EMAIL PROTEC  2008-04-10 07:53:23 
Re: Removing Item From JList - getSelectedIndex problem
CBO <christopher_board  2008-04-10 05:49:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 15:48:02 CST 2008.