鍍金池/ 教程/ Java/ Swing JMenuItem類
Swing JRadioButton
Swing Layout布局
Swing JTextField
Swing JLabel
Swing開發(fā)環(huán)境安裝
Swing JComponent類
SWING ActionEvent事件類
Swing JScrollBar
Swing教程首頁
Swing JFileChooser
SWING ContainerEvent事件處理類
Swing AdjustmentListener接口
Swing WindowAdapter類
SWING ComponentListener接口
Swing JMenuBar類
Swing JPanel類及實(shí)例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類及實(shí)例
Swing介紹
Swing MouseMotionAdapter類
SWING WindowEvent事件類
Swing ItemListener接口
SWING MouseEvent事件類
Swing JMenu類
SWING KeyEvent事件類
Swing MouseMotionListener接口
Swing JProgressBar
SWING AWTEvent事件類
Swing JRadioButtonMenuItem類及例子
Swing KeyAdapter類
SWING ActionListener接口
Swing LayoutManager接口
SWING MouseMotionEvent事件處理
Swing Component類
Swing Container類
Swing CardLayout布局
Swing MouseAdapter類
Swing JSlider
Swing KeyListener接口
Swing FocusAdapter類
Swing JColorChooser
Swing ImageIcon
Swing JComboBox
Swing GroupLayout布局類
Swing JOptionPane
Swing GridBagLayout布局類
Swing JMenuItem類
Swing MouseListener Interface
Swing事件適配器
SWING ComponentEvent處理類
SWING PaintEvent事件類
Swing FlowLayout布局類
SWING Event事件類
Swing FocusListener接口
Swing控件
Swing JButton
Swing JCheckBox
Swing SpringLayout布局類
Swing容器
Swing事件處理
Swing事件監(jiān)聽器
Swing Menu菜單類
Swing JList
Swing ContainerListener接口
Swing LayoutManager2接口
Swing JFrame類和實(shí)例
Swing JTextArea
SWING InputEvent事件類
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類及例子
Swing JSpinner
Swing GridLayout布局類
Swing JPopupMenu類及實(shí)例

Swing JMenuItem類

JMenuItem類代表實(shí)際的菜單中的項(xiàng)目。菜單中的所有項(xiàng)目應(yīng)JMenuItem的類或它的一個(gè)子類派生。默認(rèn)情況下,它體現(xiàn)了一種簡(jiǎn)單的標(biāo)記的菜單項(xiàng)。

類聲明

以下是聲明 javax.swing.JMenuItem類:

public class JMenuItem
   extends AbstractButton
      implements Accessible, MenuElement

類構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù) & 描述
1 JMenuItem() 
Creates a JMenuItem with no set text or icon.
2 JMenuItem(Action a) 
Creates a menu item whose properties are taken from the specified Action.
3 JMenuItem(Icon icon) 
Creates a JMenuItem with the specified icon.
4 JMenuItem(String text) 
Creates a JMenuItem with the specified text.
5 JMenuItem(String text, Icon icon) 
Creates a JMenuItem with the specified text and icon.
6 JMenuItem(String text, int mnemonic) 
Creates a JMenuItem with the specified text and keyboard mnemonic.

類方法

S.N. 方法 & 描述
1 protected void actionPropertyChanged(Action action, String propertyName) 
Updates the button's state in response to property changes in the associated action.
2 void addMenuDragMouseListener(MenuDragMouseListener l) 
Adds a MenuDragMouseListener to the menu item.
3 void addMenuKeyListener(MenuKeyListener l) 
Adds a MenuKeyListener to the menu item.
4 protected void configurePropertiesFromAction(Action a) 
Sets the properties on this button to match those in the specified Action.
5 protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
6 protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
7 protected void fireMenuDragMouseExited(MenuDragMouseEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
8 protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
9 protected void fireMenuKeyPressed(MenuKeyEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
10 protected void fireMenuKeyReleased(MenuKeyEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
11 protected void fireMenuKeyTyped(MenuKeyEvent event) 
Notifies all listeners that have registered interest for notification on this event type.
12 KeyStroke getAccelerator() 
Returns the KeyStroke which serves as an accelerator for the menu item.
13 AccessibleContext getAccessibleContext() 
Returns the AccessibleContext associated with this JMenuItem.
14 Component getComponent() 
Returns the java.awt.Component used to paint this object.
15 MenuDragMouseListener[] getMenuDragMouseListeners() 
Returns an array of all the MenuDragMouseListeners added to this JMenuItem with addMenuDragMouseListener().
16 MenuKeyListener[] getMenuKeyListeners() 
Returns an array of all the MenuKeyListeners added to this JMenuItem with addMenuKeyListener().
17 MenuElement[] getSubElements() 
This method returns an array containing the sub-menu components for this menu component.
18 String getUIClassID() 
Returns the suffix used to construct the name of the L&F class used to render this component.
19 protected void init(String text, Icon icon) 
Initializes the menu item with the specified text and icon.
20 boolean isArmed() 
Returns whether the menu item is "armed".
21 void menuSelectionChanged(boolean isIncluded) 
Called by the MenuSelectionManager when the MenuElement is selected or unselected.
22 protected String paramString() 
Returns a string representation of this JMenuItem.
23 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) 
Processes a key event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using MenuSelectionManager's API.
24 void processMenuDragMouseEvent(MenuDragMouseEvent e) 
Handles mouse drag in a menu.
25 void processMenuKeyEvent(MenuKeyEvent e) 
Handles a keystroke in a menu.
26 void processMouseEvent(MouseEvent e, MenuElement[] path, MenuSelectionManager manager) 
Processes a mouse event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using the MenuSelectionManager's API.
27 void removeMenuDragMouseListener(MenuDragMouseListener l) 
Removes a MenuDragMouseListener from the menu item.
28 void removeMenuKeyListener(MenuKeyListener l) 
Removes a MenuKeyListener from the menu item.
29 void setAccelerator(KeyStroke keyStroke) 
Sets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy.
30 void setArmed(boolean b) 
Identifies the menu item as "armed".
31 void setEnabled(boolean b) 
Enables or disables the menu item.
32 void setModel(ButtonModel newModel) 
Sets the model that this button represents.
33 void setUI(MenuItemUI ui) 
Sets the look and feel object that renders this component.
34 void updateUI() 
Resets the UI property with a value from the current look and feel.

方法繼承

這個(gè)類從以下類繼承的方法:

  • javax.swing.JAbstractButton

  • javax.swing.JComponent

  • java.awt.Container

  • java.awt.Component

  • java.lang.Object

JMenuItem 例子

選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >

SwingMenuDemo.java
package com.yiibai.gui;

import java.awt.*;
import java.awt.event.*;

public class SwingMenuDemo {
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel; 

   public SwingMenuDemo(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingMenuDemo  swingMenuDemo = new SwingMenuDemo();     
      swingMenuDemo.showMenuDemo();
   }
   
   private void prepareGUI(){
      mainFrame = new JFrame(上一篇:Swing MouseListener Interface下一篇:Swing介紹