Menu m = new Menu("Menu " + (menuList.size() + 1));
menuList.add(m);
mb.add(m);
Button addMenu = new Button("Add menu");
addMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Menu m = new Menu("Menu " + (menuList.size() + 1));
menuList.add(m);
mb.add(m);
}
});
final PopupMenu popup = new PopupMenu("Popup");
f.add(popup);
f.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
if (event.isPopupTrigger()) {
popup.show(f, event.getX(), event.getY());
}
}
});
f.add(addMenu, BorderLayout.NORTH);
Button addItem = new Button("Add item");
addItem.addActionListener(new ActionListener() {
int cnt = 1;
public void actionPerformed(ActionEvent event) {
for (Menu m : menuList) {
m.add(new MenuItem("Item " + cnt));
}
popup.add(new MenuItem("Item " + cnt));
cnt++;
}
});
f.add(addItem, BorderLayout.WEST);
Button addSeparator = new Button("Add separator");
addSeparator.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
for (Menu m : menuList) {
m.addSeparator();
}
popup.addSeparator();
}
});
f.add(addSeparator, BorderLayout.EAST);
Button removeItem = new Button("Remove item");
removeItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
for (Menu m : menuList) {
if (m.getItemCount() > 0)
m.remove(0);
}