Author: Maurisar Kisida
Country: Saint Lucia
Language: English (Spanish)
Genre: Music
Published (Last): 17 May 2009
Pages: 337
PDF File Size: 2.47 Mb
ePub File Size: 11.29 Mb
ISBN: 313-3-61767-400-3
Downloads: 33879
Price: Free* [*Free Regsitration Required]
Uploader: Tokasa

Display it in the text area If you specify true for the boolean argument, then the menu item is initially selected.

The bold lines of code create and connect the menu objects; the other code sets up or customizes the menu objects. This can cause problems if java swing book pdf download use any heavyweight components in your Swing program, as described in Bringing Up a Popup Menu. Once per second, the text area will be updated with information about the currently highlighted menu item, not to be confused with the menu item that the user eventually chooses.

The popup menu then appears under the cursor. A menu provides a space-saving way to let the user choose one of several options.

How to Use Menus

Other required files are listed in the example index. If you specify true for the boolean argument, then the menu item is initially selected checked.

And because JMenuBar java swing book pdf download BoxLayoutyou can customize a menu bar’s layout just by adding invisible components to it. As you can see, a menu item can have either an image or text, or both.

For example, to specify the A key, use KeyEvent. Inserts a menu item or separator into the menu at the specified position. The following figure shows many menu-related components: Otherwise, the menu item is initially unselected. To specify an accelerator you must java swing book pdf download a KeyStroke object, which combines a key specified by a KeyEvent constant and a modifier-key mask specified by an ActionEvent constant.

You can specify a mnemonic either when constructing the menu item or with the setMnemonic method. If any of your menu items performs an action that is duplicated by another menu item or by a tool-bar button, then in addition to this section you should read How to Use Actions.

The Action specifies the text and other properties of the menu see How to Use Actions. Mnemonics offer a way to use the keyboard to navigate the menu hierarchy, increasing the accessibility of programs. You can specify any of the relevant VK constants defined in the KeyEvent class. Get information from java swing book pdf download item event Here is an example of adding a glue component to a menu bar, so that the last menu is at the right edge of the menu bar:.

Java The Complete Reference 10th Edition PDF Free Download

Creates an ordinary menu item. If the argument is an integer, then it specifies the position of the menu item to be removed. By default, Swing implements a menu’s window using a lightweight component. Using Swing Components Section: Creates a menu item that looks and acts like a radio button. Lightweight popup windows are more efficient than heavyweight windows but, prior to the Java Book Java swing book pdf download 6 Update 12 release, they didn’t work well if you had any heavyweight pfd inside your GUI.

Oracle Technology Network for Java Developers | Oracle Technology Network | Oracle

For example, you can change a menu bar’s layout manager from the default left-to-right BoxLayout to something such as GridLayout. While the first menu is visible, pressing the B key with or without Alt makes the second menu item be chosen.

You can find the entire program in MenuLookDemo. Creates a popup menu.

A mnemonic is a key that makes an already visible downlosd item be chosen. The following code creates the menus shown near the beginning of this menu section. The JMenuItem ajva String arguments are treated the same as in the corresponding add methods. The following tables list the commonly used menu constructors and methods.

You might be wondering how a menu, if it’s java swing book pdf download a button, shows its menu items. To detect when the user chooses a JMenuItemyou can listen for action events just as java swing book pdf download would for a JButton.

Removes the specified prf java swing book pdf download from the menu. Other components with which the user can make a one-of-many choice include combo boxeslistsradio buttonsspinners java swing book pdf download, and tool bars.

The constructor with the Action parameter sets the menu item’s Actioncausing the menu item’s properties to be initialized from the Action. Similarly, the string argument specifies the text that the jaav item should display. The rest of this section teaches you about the menu components and tells you how to use various menu features: To see this feature, click a menu and then move the mouse over any menu item or submenu.

When the menu is activated, it uses its associated popup menu to show its menu items.