Java Reference
In-Depth Information
Table 7-7
Swing Menu Methods
METHOD
PURPOSE
EXAMPLE
setDisplayedMnemonicIndex()
Specifies which letter in the mnuFormat.setDisplayedMnemonicIndex(1);
keyword command will act
as a shortcut key.
setActionCommand()
Specifies a String that
mnuTools.setActionCommand("Tools");
can be used in the
actionPerformed() method
to test which command
was clicked.
add()
Adds commands to the
mnuBar.add(mnuFile);
JMenuBar or to a JMenu
menu.
JMenuBar()
Constructs an instance of
appMenu = new JMenuBar();
the JMenuBar object to
display as a primary menu
bar in an application.
JMenu()
Constructs an instance of JMenu = mnuFile new JMenu("File”);
the JMenu object to display JMenu = mnuFile new JMenu("Edit",
as a menu bar command.
true);
The first argument is the
displayed command
keyword. A second,
optional boolean
argument specifies if the
JMenu can act as a tear-off.
addSeparator()
Appends a new separator
mnuHelp.addSeparator();
to the end of the menu.
JMenuItem()
Constructs an instance of
JMenuItem mnuEditCopy = new
the JMenuItem object to
JMenuItem("Copy");
display as a command in
a drop-down list. The
argument is the displayed
command keyword.
addActionListener()
Enables the command to
mnuView.addActionListener(this);
hear clicks from the user,
activating the action event.
setJMenuBar()
Assigns the menu bar
setJMenuBar(appBar);
argument to the
application's interface.
 
Search WWH ::




Custom Search