Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening JInternalFrame on JMenu selection

 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use both Mnemonics and Accelerator, why didn't I think of that .

Thanks Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic