user2067787
user2067787

Reputation: 130

Hotkey for JMenuItem of JPopupMenu

I have added a JPopupMenu with certain JMenuItems to a JTable in my java application. I then set accelerators for those JMenuitems. Now my problem is that when I try to use those hotkeys, they don't work until I open that JPopupMenu. When that popup menu is open at that time, the hotkey works properly which is really useless. Please help me.

Upvotes: 4

Views: 1386

Answers (1)

camickr
camickr

Reputation: 324118

The accelerator bindings only work on components added to the GUI. A popup menu is not added to the GUI until the popup has been invoked.

You can try:

  1. Add you popup menu to the menuBar of your frame. Then the accelerator will be recognized
  2. Manually add the KeyBindings for each accelerator in you popup menu. Read the Swing tutorial on How to Use Key Bindings for more information.

Upvotes: 3

Related Questions