Search code examples
javaswingjcheckboxjpopupmenu

How do I make a JPopupMenu appear when a JCheckBox is clicked?


I have a JCheckBox in a program (labeled "Use MiniTimer") that, when right-clicked, shows a JPopupMenu with options "Show on Close", "Show on Minimize", "Show on Close or Minimize", and "Do not use MiniTimer". How can I make this JPopupMnu appear below the JCheckBox when it is left-clicked, too?

Note that I tried setting the actionPerformed method of the JCheckBox to miniTimerPopupMenu.setVisible(true);, but that merel makes the JPopupMenu appear in the top-left corner of the screen, and even then, it will not register any interactions with it. Does anyone have any experience or suggestions they would like to share?


Solution

  • Read the section from the Swing tutorial on Bringing Up a Popup Menu for a working example. The tutorial uses popup.show(...). Don't know if that is the difference.

    If you need more help post your SSCCE (http://sscce.org) that demonstrates the problem.