鍍金池/ 教程/ Java/ Swing JMenu類
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類及實例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類及實例
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類和實例
Swing JTextArea
SWING InputEvent事件類
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類及例子
Swing JSpinner
Swing GridLayout布局類
Swing JPopupMenu類及實例

Swing JMenu類

菜單類表示這是從菜單欄部署的下拉菜單組件。

類聲明

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

public class JMenu
   extends JMenuItem
      implements Accessible, MenuElement

字段域

以下是java.awt.Component類的字段:

  • protected JMenu.WinListener popupListener -- 監(jiān)聽器的彈出窗口關(guān)閉。

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

S.N. 構(gòu)造函數(shù) & 描述
1 JMenu() 
Constructs a new JMenu with no text.
2 JMenu(Action a) 
Constructs a menu whose properties are taken from the Action supplied.
3 JMenu(String s) 
Constructs a new JMenu with the supplied string as its text.
4 JMenu(String s, boolean b) 
Constructs a new JMenu with the supplied string as its text and specified as a tear-off menu or not.

類方法

S.N. 方法 & 描述
1 JMenuItem add(Action a) 
Creates a new menu item attached to the specified Action object and appends it to the end of this menu.
2 Component add(Component c) 
Appends a component to the end of this menu.
3 Component add(Component c, int index) 
Adds the specified component to this container at the given position.
4 JMenuItem add(JMenuItem menuItem) 
Appends a menu item to the end of this menu.
5 JMenuItem add(String s) 
Creates a new menu item with the specified text and appends it to the end of this menu.
6 void addMenuListener(MenuListener l) Adds a listener for menu events.
7 void addSeparator() 
Appends a new separator to the end of the menu.
8 void applyComponentOrientation(ComponentOrientation o) 
Sets the ComponentOrientation property of this menu and all components contained within it.
9 protected PropertyChangeListener createActionChangeListener(JMenuItem b) 
Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.
10 protected JMenuItem createActionComponent(Action a) 
Factory method which creates the JMenuItem for Actions added to the JMenu.
11 protected JMenu.WinListener createWinListener(JPopupMenu p) 
Creates a window-closing listener for the popup.
12 void doClick(int pressTime) 
Programmatically performs a "click".
13 protected void fireMenuCanceled() 
Notifies all listeners that have registered interest for notification on this event type.
14 protected void fireMenuDeselected() 
Notifies all listeners that have registered interest for notification on this event type.
15 protected void fireMenuSelected() 
Notifies all listeners that have registered interest for notification on this event type.
16 AccessibleContext getAccessibleContext() 
Gets the AccessibleContext associated with this JMenu.
17 Component getComponent() 
Returns the java.awt.Component used to paint this MenuElement.
18 int getDelay() 
Returns the suggested delay, in milliseconds, before submenus are popped up or down.
19 JMenuItem getItem(int pos) 
Returns the JMenuItem at the specified position.
20 int getItemCount() 
Returns the number of items on the menu, including separators.
21 Component getMenuComponent(int n) 
Returns the component at position n.
22 int getMenuComponentCount() 
Returns the number of components on the menu.
23 Component[] getMenuComponents() 
Returns an array of Components of the menu's subcomponents.
24 MenuListener[] getMenuListeners() 
Returns an array of all the MenuListeners added to this JMenu with addMenuListener().
25 JPopupMenu getPopupMenu() 
Returns the popupmenu associated with this menu.
26 protected Point getPopupMenuOrigin() 
Computes the origin for the JMenu's popup menu.
27 MenuElement[] getSubElements() 
Returns an array of MenuElements containing the submenu for this menu component.
28 String getUIClassID() 
Returns the name of the L&F class that renders this component.
29 JMenuItem insert(Action a, int pos) 
Inserts a new menu item attached to the specified Action object at a given position.
30 JMenuItem insert(JMenuItem mi, int pos) 
Inserts the specified JMenuitem at a given position.
31 void insert(String s, int pos) 
Inserts a new menu item with the specified text at a given position.
32 void insertSeparator(int index) 
Inserts a separator at the specified position.
33 boolean isMenuComponent(Component c) 
Returns true if the specified component exists in the submenu hierarchy.
34 boolean isPopupMenuVisible() 
Returns true if the menu's popup window is visible.
35 boolean isSelected() 
Returns true if the menu is currently selected (highlighted).
36 boolean isTearOff() 
Returns true if the menu can be torn off.
37 boolean isTopLevelMenu() 
Returns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.
38 void menuSelectionChanged(boolean isIncluded) 
Messaged when the menubar selection changes to activate or deactivate this menu.
39 protected String paramString() 
Returns a string representation of this JMenu.
40 protected void processKeyEvent(KeyEvent evt) 
Processes key stroke events such as mnemonics and accelerators.
41 void remove(Component c) 
Removes the component c from this menu.
42 void remove(int pos) 
Removes the menu item at the specified index from this menu.
43 void remove(JMenuItem item) 
Removes the specified menu item from this menu.
44 void removeAll() 
Removes all menu items from this menu.
45 void removeMenuListener(MenuListener l) 
Removes a listener for menu events.
46 void setAccelerator(KeyStroke keyStroke) 
setAccelerator is not defined for JMenu.
47 void setComponentOrientation(ComponentOrientation o)
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
48 void setDelay(int d) 
Sets the suggested delay before the menu's PopupMenu is popped up or down.
49 void setMenuLocation(int x, int y) 
Sets the location of the popup component.
50 void setModel(ButtonModel newModel) 
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.
51 void setPopupMenuVisible(boolean b) 
Sets the visibility of the menu's popup.
52 void setSelected(boolean b) 
Sets the selection status of the menu.
53 void updateUI() 
Resets the UI property with a value from the current look and feel.

方法繼承

這個類從以下類繼承的方法:

  • javax.swing.JAbstractButton

  • javax.swing.JComponent

  • java.awt.Container

  • java.awt.Component

  • java.lang.Object

JMenu 例子

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

SwingMenuDemo.java
上一篇:Swing JList下一篇:Swing SpringLayout布局類