~/ learn/ comp-308/ cards/ Menus, dialogs & shortcuts
1 of 7

Type a File menu with a mnemonic, added to a menu bar on the frame

Type a File menu with a mnemonic, added to a menu bar on the frame

Answer

JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); JMenuBar bar = new JMenuBar(); bar.add(file); frame.setJMenuBar(bar);

setMnemonic gives Alt+F to open the menu; setJMenuBar (not add) installs the bar in the frame’s menu slot.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/380f7d77-1917-4278-a1a0-aa09a895f61b/flashcard utf-8 LF