[SOLVED][SWING][LWJGL] JMenu doesnt give up Focus when clicking on LWJGL-Canvas.

Hello everyone.

I have a (probably) easy to solve problem:
I got a simple Canvas with a LWJGL-Display bound to it using ‘Display.setParent(…)’.
Above the Canvas is a completely fine JMenuBar with JMenu’s in it.

Now, when I go and click on one of these Menu’s, then try to click on the Canvas, the Menu will not give its focus to the Canvas.

Googling for half an hour gave no results, except this:

Is there no way to give the Canvas the focus?

Thanks in advance for the help, and have a nice day.

  • Longor1996

I hate Swing for being so damn complex.


I think I just solved it on my own.
It works by putting all the JMenu’s in an array, and when the User clicks into the Canvas, do this:


for_each MENU in MENUS
{
-   menu.setEnabled(false);
-   menu.updateUI();
-   menu.setEnabled(true);
  // The above one throws an exception. This one doesn't.
  menu.setVisible(false);
  menu.updateUI();;
  menu.setVisible(true);
  menu.setPopupMenuVisible(false);
  menu.repaint();
}

It’s somehow funny that this works.
If anyone has a better Idea (that is not just the work of an unintentional side-effect), say it! :slight_smile: