How can I handle adding JMenuItem
(newItem
) to the JMenu
(menuUsers
)? Is there a proper ActionListener
for this purpose? There is a part of code that performs adding menu items to menu. It performs when some event is raised. Here it is:
public void UpdateUserList(Map<String, UserSchedule> allSchedule) throws Exception {
menuUsers.removeAll();
Iterator it = allSchedule.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
JMenuItem newItem = new JMenuItem(entry.getKey().toString());
newItem.setName("User");
menuUsers.add(newItem);
}
}
I'd like to be like this (pseudo-code):
menuUsers.addSomeListener(new SomeListener()
{
void performWhenNewItemAdded(...) {
...
}
}