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(); // revalidat开发者_StackOverflowe
            //popup.remove(0); // removing first (0) menu item
        }
    }
Almost there! :) (yes, I tried Google and JavaDocs)
If I've understood what you're after correctly, you want the removeAll() method on JMenu; See the Javadoc here.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论