~/ 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/27f5163f-390e-4c37-893d-a9e195435bba/flashcard utf-8 LF