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
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
選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >
SwingMenuDemo.javapackage 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介紹