Re: how to delete a JList element
On Sat, 21 Jun 2008 21:01:21 +0000, thufir wrote:
This seems to give a NullPointerException, as below, because the backing
collection is a DefaultListModel:
I got basically the same result when trying to change the backing
DefaultListModel directly:
thufir@arrakis:~/bcit-comp2611-project2$
thufir@arrakis:~/bcit-comp2611-project2$ head src/a00720398/view/
NewJFrame.java -n 481 | tail -n 10
private void deleteGuestActionPerformed(java.awt.event.ActionEvent
evt)//GEN-FIRST:event_deleteGuestActionPerformed
{//GEN-HEADEREND:event_deleteGuestActionPerformed
int i =guestList.getSelectedIndex();
BedAndBreakfast bnb = BedAndBreakfast.getInstance(); //the
"database"
System.out.println("delete guest \t" + i + bnb.getGuests().get(i));
//((DefaultListModel)(guestList.getModel())).removeElementAt(i);
bnb.getGuests().removeElementAt(i);
}//GEN-LAST:event_deleteGuestActionPerformed
thufir@arrakis:~/bcit-comp2611-project2$
it runs and, apparently, works but there are still run time
java.lang.NullPointerException errors.
I can change bnb.getGuests() to return a Map, but then HashMap doesn't
convert nicely to an array...
I assume that the NullPointerException is because DefaultListModel
doesn't nicely handle a change of index?
-Thufir