I have a JMenu populated with JMenuItems from a database that have listeners, one of them being to delete the entry from the database if selected. When this happens that JMenuItem should disappear from the menus. Here's a short bit as an example
for (final Racer r : Racer.getAllRacers()) {
JMenuItem j = new JMenuItem(r.getName());
racerDelete.add(j);
j.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int reply = JOptionPane.showConfirmDialog(null,
"Are you sure you want to delete racer " + r.getName() + "?", "Delete?",
JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION){
r.delete();
racerDelete.remove(???);
}
}
});
}
So what can I put in place of the "???"? The fields of r are about all I have to identify the JMenuItem. I already tried racerDelete.remove(j) which doesnt work and I'm not sure why.