所有类


javax.swing
类 JPopupMenu

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JPopupMenu
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, MenuElement
直接已知子类:
BasicComboPopup

public class JPopupMenu
   
   
   
   
   
extends JComponent
implements Accessible, MenuElement

弹出菜单的实现,弹出菜单是一个可弹出并显示一系列选项的小窗口。JPopupMenu 用于用户在菜单栏上选择项时显示的菜单。它还用于当用户选择菜单项并激活它时显示的“右拉式 (pull-right)”菜单。最后,JPopupMenu 还可以在想让菜单显示的任何其他位置使用。例如,当用户在指定区域中右击时。

有关使用弹出菜单的示例的信息,请参阅《The Java Tutorial》中的 How to Use Menus

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder


嵌套类摘要
protected  class JPopupMenu.AccessibleJPopupMenu
          此类实现 JPopupMenu 类的可访问性支持。
static class JPopupMenu.Separator
          弹出与菜单有关的分隔符。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JPopupMenu()
          构造一个不带“调用者”的 JPopupMenu
JPopupMenu(String label)
          构造一个具有指定标题的 JPopupMenu
 
方法摘要
 JMenuItem add(Action a)
          将指派指定 Action 对象的新菜单项追加到菜单的末尾。
 JMenuItem add(JMenuItem menuItem)
          将指定菜单项追加到此菜单的末尾。
 JMenuItem add(String s)
          创建具有指定文本的菜单项,并将其追加到此菜单的末尾。
 void addMenuKeyListener(MenuKeyListener l)
          将 MenuKeyListener 添加到弹出菜单。
 void addPopupMenuListener(PopupMenuListener l)
          添加 PopupMenu 侦听器。
 void addSeparator()
          将新分隔符追加到菜单的末尾。
protected  PropertyChangeListener createActionChangeListener(JMenuItem b)
          返回一个正确配置的 PropertyChangeListener,它在 Action 发生更改时更新控件。
protected  JMenuItem createActionComponent(Action a)
          该工厂方法为添加到 JPopupMenuAction 创建对应的 JMenuItem
protected  void firePopupMenuCanceled()
          通知 PopupMenuListener 此弹出菜单将被取消。
protected  void firePopupMenuWillBecomeInvisible()
          通知 PopupMenuListener 此弹出菜单将变得不可见。
protected  void firePopupMenuWillBecomeVisible()
          通知 PopupMenuListener 此弹出菜单将变得可见。
 AccessibleContext getAccessibleContext()
          获取与此 JPopupMenu 关联的 AccessibleContext。
 Component getComponent()
          返回此 JPopupMenu 组件。
 Component getComponentAtIndex(int i)
          已过时。 getComponent(int i) 取代
 int getComponentIndex(Component c)
          返回指定组件的索引。
static boolean getDefaultLightWeightPopupEnabled()
          获取 defaultLightWeightPopupEnabled 属性,默认情况下,该属性为 true
 Component getInvoker()
          返回作为此弹出菜单的“调用者”的组件。
 String getLabel()
          返回弹出菜单的标签
 Insets getMargin()
          返回弹出菜单的边框与其包含内容之间的空白(以像素表示)。
 MenuKeyListener[] getMenuKeyListeners()
          返回利用 addMenuKeyListener() 添加到此 JPopupMenu 的所有 MenuKeyListener 组成的数组。
 PopupMenuListener[] getPopupMenuListeners()
          返回利用 addPopupMenuListener() 添加到此 JMenuItem 的所有 PopupMenuListener 组成的数组。
 SingleSelectionModel getSelectionModel()
          返回处理单个选择的模型对象。
 MenuElement[] getSubElements()
          返回 MenuElement 组成的数组,包含此菜单组件的子菜单。
 PopupMenuUI getUI()
          返回用于呈现此组件的外观 (L&F) 对象。
 String getUIClassID()
          返回用于呈现此组件的 L&F 类名。
 void insert(Action a, int index)
          在给定位置插入对应于指定 Action 对象的菜单项。
 void insert(Component component, int index)
          将指定组件插入到菜单的给定位置。
 boolean isBorderPainted()
          检查是否应该绘制边框。
 boolean isLightWeightPopupEnabled()
          获取 lightWeightPopupEnabled 属性。
 boolean isPopupTrigger(MouseEvent e)
          如果 JPopupMenu 的当前安装 UI 将 MouseEvent 视为弹出菜单触发器,则返回 true。
 boolean isVisible()
          如果弹出菜单可见(当前显示的),则返回 true。
 void menuSelectionChanged(boolean isIncluded)
          当菜单栏选择发生更改以激活或取消激活此菜单时传递消息。
 void pack()
          布置容器,让它使用显示其内容所需的最小空间。
protected  void paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制弹出菜单的边框。
protected  String paramString()
          返回此 JPopupMenu 的字符串表示形式。
protected  void processFocusEvent(FocusEvent evt)
          处理组件上发生的焦点事件,方法是将其指派到任意已注册的 FocusListener 对象。
protected  void processKeyEvent(KeyEvent evt)
          处理快捷键事件,如助记符和加速器。
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
          通过使用 MenuSelectionManager 的 API 处理从 MenuSelectionManager 转发的键事件,并在需要时更改菜单选择。
 void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
          要求此方法遵守 MenuElement 接口,但它没有被实现。
 void remove(int pos)
          从此弹出菜单移除指定索引处的组件。
 void removeMenuKeyListener(MenuKeyListener l)
          从弹出菜单移除 MenuKeyListener
 void removePopupMenuListener(PopupMenuListener l)
          移除 PopupMenu 侦听器。
 void setBorderPainted(boolean b)
          设置是否应该绘制边框。
static void setDefaultLightWeightPopupEnabled(boolean aFlag)
          设置 lightWeightPopupEnabled 属性的默认值。
 void setInvoker(Component invoker)
          设置弹出菜单的调用者,即弹出菜单在其中显示的组件。
 void setLabel(String label)
          设置弹出菜单的标签。
 void setLightWeightPopupEnabled(boolean aFlag)
          设置 lightWeightPopupEnabled 属性的值,默认情况下该值为 true
 void setLocation(int x, int y)
          使用 X、Y 坐标设置弹出菜单的左上角的位置。
 void setPopupSize(Dimension d)
          使用 Dimension 对象设置弹出窗口的大小。
 void setPopupSize(int width, int height)
          将弹出窗口的大小设置为指定的宽度和高度。
 void setSelected(Component sel)
          设置当前选择的组件,此方法将更改选择模型。
 void setSelectionModel(SingleSelectionModel model)
          设置处理单个选择的模型对象。
 void setUI(PopupMenuUI ui)
          设置呈现此组件的 L&F 对象。
 void setVisible(boolean b)
          设置弹出菜单的可见性。
 void show(Component invoker, int x, int y)
          在组件调用者的坐标空间中的位置 X、Y 显示弹出菜单。
 void updateUI()
          将 UI 属性重置为一个当前外观对应的值。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

JPopupMenu

public JPopupMenu()
构造一个不带“调用者”的 JPopupMenu


JPopupMenu

public JPopupMenu(String label)
构造一个具有指定标题的 JPopupMenu

参数:
label - 可以被 UI 用作弹出菜单的标题显示的字符串。
方法详细信息

setDefaultLightWeightPopupEnabled

public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
设置 lightWeightPopupEnabled 属性的默认值。

参数:
aFlag - 如果弹出菜单为轻量级,则为 true;否则为 false
另请参见:
getDefaultLightWeightPopupEnabled(), setLightWeightPopupEnabled(boolean)

getDefaultLightWeightPopupEnabled

public static boolean getDefaultLightWeightPopupEnabled()
获取 defaultLightWeightPopupEnabled 属性,默认情况下,该属性为 true

返回:
defaultLightWeightPopupEnabled 属性的值
另请参见:
setDefaultLightWeightPopupEnabled(boolean)

getUI

public PopupMenuUI getUI()
返回用于呈现此组件的外观 (L&F) 对象。

返回:
呈现此组件的 PopupMenuUI 对象

setUI

public void setUI(PopupMenuUI ui)
设置呈现此组件的 L&F 对象。

参数:
ui - 新 PopupMenuUI L&F 对象
另请参见:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
将 UI 属性重置为一个当前外观对应的值。

覆盖:
JComponent 中的 updateUI
另请参见:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
返回用于呈现此组件的 L&F 类名。

覆盖:
JComponent 中的 getUIClassID
返回:
字符串 "PopupMenuUI"
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部