-
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.
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
-
It should be one line of code (like you already have):
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.
-
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