2

I got the JMenu down except for removing. :D I mean, I can do popup.remove(NUMBER) but that can cause NPE errors. So, is there a way to remove all JMenuItems from JMenu?

Here's my update checkPopup() if anyone's interested:

            private void checkPopup(MouseEvent e)
    {
        if (e.isPopupTrigger())
        {

            int itemSelectx = listbox.getSelectedIndex();
            Object actItemx = listbox.getModel().getElementAt(itemSelectx);
            System.out.println("You pressed on " + actItemx);

        if (actItemx == "Item 1") {
            popup.add(cancelMenuItem); // add the ability to cancel an item
            popup.add(dropMenuItem); // add ability to drop the item
        }

            popup.show(inv.this, e.getX(), e.getY()); // show item at mouse
            popup.revalidate(); // revalidate
            //popup.remove(0); // removing first (0) menu item
        }
    }

Almost there! :) (yes, I tried Google and JavaDocs)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
test
  • 17,706
  • 64
  • 171
  • 244
  • the reason your google search didn't work was because you looked for JListMenu instead of JMenu :-) – Zach L Feb 02 '11 at 23:42

1 Answers1

7

If I've understood what you're after correctly, you want the removeAll() method on JMenu; See the Javadoc here.

Michael Berry
  • 70,193
  • 21
  • 157
  • 216