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 > Removing Item F...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 15947 of 16466
Post > Topic >>

Removing Item From JList - getSelectedIndex problem

by CBO <christopher_board@[EMAIL PROTECTED] > Apr 9, 2008 at 03:21 AM

Hi all,

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.

Thank you
 




 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 Mon Oct 6 10:49:11 CDT 2008.