0
JButton jButton1 = new JButton("Click Me");

public void showPopupMenu1(JButton invoker){
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.setLayout(new GridLayout(5, 1));
    JMenu menu = new JMenu("Other");
    menu.add(new JMenuItem("A"));
    menu.add(new JMenuItem("B"));
    menu.add(new JMenuItem("C"));
    popupMenu.add(menu);
    popupMenu.add(new JButton("Apple"));
    popupMenu.add(new JButton("Banana"));
    popupMenu.add(new JButton("Carrot"));
    popupMenu.add(new JButton("Orange"));
    popupMenu.show(invoker, 0, invoker.getHeight());
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{                                         
    showPopupMenu1(jButton1);
}

When the cursor goes to Apple Button, the menu's popup will not close and still marked as selected.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
imarefe
  • 5
  • 4
  • why do you add buttons? – kleopatra Apr 01 '13 at 11:11
  • whether I add buttons or JPanel or JList, the behavior is still the same. I just want to customized JMenuItem but when I did, menu's popup will not close every time the cursor goes to the next item which is a button or a panel. – imarefe Apr 04 '13 at 05:41

0 Answers0