Fullscreen mode and keyboard acceleration

2006 May 23 at 07:22 » Tagged as :

While working on Rad Image Viewer, I ran into an issue with keyboard acceleration in full screen mode.

By setting a keyboard accelerator for a JMenuItem, makes it possible to invoke the action without navigating through the menu. The action can be invoked by a keystroke. In short this is java speak for short cut keys. The trouble is keyboard accelerators work fine as long as you are not in full screen mode. The moment you get into full screen mode, short cuts are completely ignored.

Lot of hair pulling and Googling didn't lead to a solution. So Rad Image 0.91 was released without acceleration in full screen mode. Did another search today and was pleasently suprised to find a solution.

Halfway across the world a guy I know by his nick (afishionado) had encountered the same problem at the same time and fortunately for me found a solution. Even more fortunately he had taken the trouble to share it.

His solution is to use JFrame instead of JWindow. So why does the API and the sample codes all suggest the use of JWindow? The solution mentioned above suggests using undecorated JFrameS however the moment the decorations were removed accelerators stopped working.

An alternative to accelerators is to use a KeyListener. KeyListeners are more complicated and involve a bit of extra code. However I found that KeyListeners worked in full screen mode regardlesss of whether the frame is decorated or not. However they still failed with a JWindow was used instead of a JFrame.