Question

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?

Was it helpful?

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.

OTHER TIPS

I think you should set the location of the miniTimerPopupMenu using the setLocation() method, I think the following code does the trick

    miniTimerPopupMenu.setLocation((int)jCheckBox.getLocation().getX(),(int)jCheckBox.getLocation().getY()-10);
    miniTimerPopupMenu.setVisible(true);

Then you can play with y and x location of the top popupmenu.

Hope this works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top