// removeAll on hide!!! public void show(Component invoker, int x, int y) { ControlPanel panel = (ControlPanel) invoker.getParent(); control = (LawControl) panel.getControl(); removeAll(); String[] names = control.getPresetNames(); if (names == null) return; for (int i = 0; i < names.length; i++) { JMenuItem item = new JMenuItem(names[i]); add(item); item.addActionListener(this); } // create dynamic menu here super.show(invoker, x, y); }
public void actionPerformed(ActionEvent event) { control.applyPreset(event.getActionCommand()); }