Results 1 to 3 of 3

Thread: JList

  1. #1
    nawl is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default JList

    When trying to remove items from a JList, the element is deleted (as to say it is no longer selectable,) but the image of the words still stays there, and I am unable to add anything else after that.

    Java Code:
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            Contact contct = contactList.get(selectedIndex);
            try {
                contact.removeFromFile(contct);
            } catch (IOException ioe) {
                System.out.println("write failed\n");
            }
            listModel.removeElementAt(selectedIndex);
            jList1.clearSelection();
        }
    Thanks

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    It should be one line of code (like you already have):

    Java Code:
    listModel.removeElementAt(selectedIndex);
    Make sure the code is executed on the Event Dispatch Thread and there should not be any problems. Read the JList API and follow the link to the section in the Swing tutorial on "How to Use Lists". The example there shows you how to dynamically and and remove an item, so follow the code from the example.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    To get better help sooner, post a SSCCE* that clearly demonstrates your problem.
    * SSCCE : Java Glossary

    Not all your code, and certainly not reams of IDE-generated autocode.

    db

Similar Threads

  1. How to use a JList?
    By glhansen in forum New To Java
    Replies: 3
    Last Post: 03-24-2009, 11:27 AM
  2. DnD - JList indices
    By carderne in forum New To Java
    Replies: 0
    Last Post: 03-09-2009, 07:03 AM
  3. JList
    By pinks_70986 in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 09:36 AM
  4. About JList
    By hungleon88 in forum Advanced Java
    Replies: 5
    Last Post: 08-30-2008, 10:24 PM
  5. Help with JList
    By Albert in forum NetBeans
    Replies: 1
    Last Post: 07-13-2007, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •