views:

28

answers:

2

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?

+1  A: 

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

Feras
I, in fact, did exactly that. It appears in the right place, but still, as I said in the question, it refuses to accept interactions.
Supuhstar
if you mean adding action listener to popupMenu try this link http://www.java2s.com/Tutorial/Java/0240__Swing/Addingactionlistenertopopupmenuitem.htm
Feras
no, all the actionListeners are there. It simply won't register that a mouse has entere, exited, clicked, hovered, or dragged within it. Nor will it register keystrokes.
Supuhstar
Disregard that last comment. It seems to be working, now. Thank you!
Supuhstar
+1  A: 

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.

camickr