GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Opening JInternalFrame on JMenu selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Opening JInternalFrame on JMenu selection" Watch "Opening JInternalFrame on JMenu selection" New topic
Author

Opening JInternalFrame on JMenu selection

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Okay I'm stuck at a little problem. I'm creating a desktop application which uses JDesktopPane and JInternalFrame. Now the main window which contains these internal frames has a menu bar. Some of the menu's don't have any options in them. Instead I have to open a JInternalFrame when the menu is clicked (I know it sounds a little weird but I can't help it). I did it using menuListener on the JMenu. The problem is that the JInternalFrame doesn't gets focus as the empty menu has the focus. I tried to get focus in the internal frame using requestFocus, grabFocus, and setSelected but none worked (I called these methods after the internal frame was visible as I read that they don't work before the frame is visible). As an alternative I tried to add JMenuItem to JMenuBar, it took the full width which I controlled using setMaximumSize. The internal frame is getting focus but the problem in this case is that the shortcut key that I set for this menu item (using setMnemonic) doesn't work. Does anyone know how to either get the internal frame to focus when using JMenu or get the shortcut to work if I put JMenuItem to JMenuBar...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
worked OK for me, in a simple demo program.
setAccelerator seems to work OK when the menuItem is added directly to the menuBar (leaving setMnemonic to show the underlined shortcut key)

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Use both Mnemonics and Accelerator, why didn't I think of that .

Thanks Michael
 
GeeCON Prague 2014
 
subject: Opening JInternalFrame on JMenu selection