public class JPopupMenu extends JComponent implements Accessible, MenuElement
JPopupMenu
用于显示当用户选择菜单栏上的菜单项。它也用于“拉右”菜单,当选择一个激活它的菜单项时出现。最后,一个
JPopupMenu
也可以用于其他任何你想要的菜单出现。例如,当用户在指定区域内单击右键时。
对于使用弹出菜单信息和例子,看到How to Use Menus在java教程。
警告: Swing是线程不安全的。更多信息见Swing's Threading Policy。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
protected class |
JPopupMenu.AccessibleJPopupMenu
这个类实现了对
JPopupMenu 类可访问性支持。
|
static class |
JPopupMenu.Separator
一个弹出式菜单具体分离器。
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JPopupMenu()
构建了一个
JPopupMenu 没有“调用”。
|
JPopupMenu(String label)
构建了一个具有指定名称
JPopupMenu 。
|
Modifier and Type | Method and Description |
---|---|
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)
工厂方法创建的
JMenuItem
Actions 添加到
JPopupMenu 。
|
protected void |
firePopupMenuCanceled()
通知
PopupMenuListeners 这个弹出菜单被取消。
|
protected void |
firePopupMenuWillBecomeInvisible()
通知
PopupMenuListener s这个弹出菜单将成为无形。
|
protected void |
firePopupMenuWillBecomeVisible()
通知
PopupMenuListener s这个弹出菜单将变得可见。
|
AccessibleContext |
getAccessibleContext()
获取与此相关的accessiblecontext Jpopupmenu的。
|
Component |
getComponent()
返回此
JPopupMenu 组件。
|
Component |
getComponentAtIndex(int i)
过时的。
|
int |
getComponentIndex(Component c)
返回指定组件的索引。
|
static boolean |
getDefaultLightWeightPopupEnabled()
得到
defaultLightWeightPopupEnabled 属性,默认为
true 。
|
Component |
getInvoker()
收益是这个弹出式菜单的调用的组件。
|
String |
getLabel()
返回弹出菜单的标签
|
Insets |
getMargin()
返回在像素的边缘,弹出菜单的边框和容器之间。
|
MenuKeyListener[] |
getMenuKeyListeners()
返回所有的
MenuKeyListener s数组添加到这个Jpopupmenu的与addmenukeylistener()。
|
PopupMenuListener[] |
getPopupMenuListeners()
返回所有的
PopupMenuListener s数组添加到该菜单项与addpopupmenulistener()。
|
SingleSelectionModel |
getSelectionModel()
返回处理单个选择的模型对象。
|
MenuElement[] |
getSubElements()
返回包含此菜单组件的子菜单
MenuElement s数组。
|
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)
如果
MouseEvent 被
JPopupMenu 目前安装界面弹出触发返回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 变化的菜单选择,如果需要转发,利用
MenuSelectionManager 的API。
|
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属性从目前看价值和感觉。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
public JPopupMenu()
JPopupMenu
没有“调用”。
public JPopupMenu(String label)
JPopupMenu
。
label
,UI可以使用显示弹出式菜单的标题字符串。
public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled
属性的默认值。
aFlag
-
true
如果弹出窗口可以是轻量级的,否则
false
getDefaultLightWeightPopupEnabled()
,
setLightWeightPopupEnabled(boolean)
public static boolean getDefaultLightWeightPopupEnabled()
defaultLightWeightPopupEnabled
属性,默认为
true
。
defaultLightWeightPopupEnabled
属性的值
setDefaultLightWeightPopupEnabled(boolean)
public PopupMenuUI getUI()
PopupMenuUI
对象,使得这部分
public void setUI(PopupMenuUI ui)
ui
-新的
PopupMenuUI
L和F的对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI
方法重写,继承类
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
方法重写,继承类
JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
protected void processFocusEvent(FocusEvent evt)
Component
FocusListener
对象的事件。
此方法不调用,除非此组件启用焦点事件。当下列情况之一发生时,将启用焦点事件:
FocusListener
对象是通过addFocusListener
注册。enableEvents
。如果焦点事件是一个Component
启用,目前KeyboardFocusManager
决定是否或不是一个焦点事件可以被发送到注册FocusListener
对象。如果事件是被派遣的KeyboardFocusManager
调用Component
的dispatchEvent
方法,结果在一个叫到Component
的processFocusEvent
方法。
如果焦点事件是一个Component
启用,以FocusEvent
作为参数调用Component
的dispatchEvent
方法将导致一个电话到Component
的processFocusEvent
方法无论当前KeyboardFocusManager
。
注意,如果参数是null
行为是不可能导致异常。
protected void processKeyEvent(KeyEvent evt)
processKeyEvent
方法重写,继承类
JComponent
evt
-待处理的关键事件
KeyEvent
,
KeyListener
,
KeyboardFocusManager
,
DefaultKeyboardFocusManager
,
Component.processEvent(java.awt.AWTEvent)
,
Component.dispatchEvent(java.awt.AWTEvent)
,
Component.addKeyListener(java.awt.event.KeyListener)
,
Component.enableEvents(long)
,
Component.isShowing()
public SingleSelectionModel getSelectionModel()
selectionModel
财产
SingleSelectionModel
public void setSelectionModel(SingleSelectionModel model)
model
-新的
SingleSelectionModel
SingleSelectionModel
public JMenuItem add(JMenuItem menuItem)
menuItem
-
JMenuItem
添加
JMenuItem
public JMenuItem add(Action a)
Action
对象结束。
a
-
Action
添加到菜单
Action
protected JMenuItem createActionComponent(Action a)
JMenuItem
Actions
添加到
JPopupMenu
。
a
为菜单项被添加的
Action
Action
protected PropertyChangeListener createActionChangeListener(JMenuItem b)
PropertyChangeListener
更新控制在
Action
发生变化。
public void remove(int pos)
remove
方法重写,继承类
Container
pos
-物品的位置被删除
IllegalArgumentException
-如果
pos
< 0的值,或者如果
pos
值大于物品的数量
Container.add(java.awt.Component)
,
Container.invalidate()
,
Container.validate()
,
Container.getComponentCount()
public void setLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled
属性值,默认为
true
。默认情况下,当一个外观,显示一个弹出窗口,可以选择使用一个轻量级(java)弹出。轻量级的弹出窗口比重量级更有效(本地同行)窗口,但轻量级和重量级组件不能很好地融合在一个GUI。如果你的应用程序和轻量级和重量级组件,你应该禁用轻量级的弹出窗口。一些看起来和感觉可能总是使用重量级的弹出窗口,不管这个属性的值。
aFlag
-
false
禁用轻量级的弹出窗口
isLightWeightPopupEnabled()
public boolean isLightWeightPopupEnabled()
lightWeightPopupEnabled
财产。
lightWeightPopupEnabled
属性的值
setLightWeightPopupEnabled(boolean)
public String getLabel()
setLabel(java.lang.String)
public void setLabel(String label)
label
-指定弹出式菜单的标签
setLabel(java.lang.String)
public void addSeparator()
public void insert(Action a, int index)
Action
对象在一个给定的位置。
a
-插入
Action
对象
index
-指定的位置插入
Action
,其中0是第一个
IllegalArgumentException
-如果
index
<0
Action
public void insert(Component component, int index)
component
-
Component
插入
index
-指定的位置插入成分,其中0是第一个
IllegalArgumentException
-如果
index
<0
public void addPopupMenuListener(PopupMenuListener l)
PopupMenu
听众。
l
-
PopupMenuListener
添加
public void removePopupMenuListener(PopupMenuListener l)
PopupMenu
听众。
l
-
PopupMenuListener
删除
public PopupMenuListener[] getPopupMenuListeners()
PopupMenuListener
s数组添加到该菜单项与addpopupmenulistener()。
PopupMenuListener
s说如果没有听众已添加一个空数组
public void addMenuKeyListener(MenuKeyListener l)
MenuKeyListener
的弹出式菜单。
l
-
MenuKeyListener
加以补充
public void removeMenuKeyListener(MenuKeyListener l)
MenuKeyListener
。
l
-
MenuKeyListener
被删除
public MenuKeyListener[] getMenuKeyListeners()
MenuKeyListener
s数组添加到这个Jpopupmenu的与addmenukeylistener()。
MenuKeyListener
s说如果没有听众已添加一个空数组
protected void firePopupMenuWillBecomeVisible()
PopupMenuListener
s这个弹出菜单将变得可见。
protected void firePopupMenuWillBecomeInvisible()
PopupMenuListener
s这个弹出菜单将成为无形。
protected void firePopupMenuCanceled()
PopupMenuListeners
这个弹出菜单被取消。
public void pack()
public void setVisible(boolean b)
setVisible
方法重写,继承类
JComponent
b
真使弹出可见,或假隐藏它
Component.isVisible()
,
Component.invalidate()
public boolean isVisible()
isVisible
方法重写,继承类
Component
true
如果组件是可见的,
false
否则
Component.setVisible(boolean)
public void setLocation(int x, int y)
该方法改变了几何相关的数据。因此,本地窗口系统可以忽略这些要求,也可以修改请求的数据,使JPopupMenu
对象被放置和大小的一种方式,密切对应的桌面设置。
setLocation
方法重写,继承类
Component
x
的x坐标的弹出的新位置在屏幕的坐标空间
y
在屏幕坐标空间弹出的新位置的y坐标
Component.getLocation()
,
Component.setBounds(int, int, int, int)
,
Component.invalidate()
public Component getInvoker()
Component
弹出式菜单显示
public void setInvoker(Component invoker)
invoker
-
Component
,将显示一个弹出式菜单
public void show(Component invoker, int x, int y)
invoker
在弹出菜单中出现的空间构成
x
- x坐标在调用者的坐标空间,在弹出菜单被显示
y
- Y坐标在调用者的坐标空间,在弹出菜单被显示
@Deprecated public Component getComponentAtIndex(int i)
Container.getComponent(int)
i
-组件的指数,其中0是第一个
Component
public int getComponentIndex(Component c)
c
-
Component
找到
public void setPopupSize(Dimension d)
Dimension
对象。这相当于
setPreferredSize(d)
。
d
-
Dimension
指定这个组件的新尺寸。
public void setPopupSize(int width, int height)
setPreferredSize(new Dimension(width, height))
。
width
-像素的弹出式窗口的新的宽度
height
-像素的弹出式窗口的新高度
public void setSelected(Component sel)
sel
-
Component
选择
public boolean isBorderPainted()
setBorderPainted(boolean)
public void setBorderPainted(boolean b)
b
-如果是真的,边界是画。
isBorderPainted()
protected void paintBorder(Graphics g)
borderPainted
属性
true
。
paintBorder
方法重写,继承类
JComponent
g
-
Graphics
对象
JComponent.paint(java.awt.Graphics)
,
JComponent.setBorder(javax.swing.border.Border)
public Insets getMargin()
Insets
对象。
protected String paramString()
JPopupMenu
字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能会在实现过程中有所不同。返回的字符串是空的但可能不
null
。
paramString
方法重写,继承类
JComponent
JPopupMenu
字符串表示形式。
public AccessibleContext getAccessibleContext()
getAccessibleContext
接口
Accessible
getAccessibleContext
方法重写,继承类
Component
public void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
MenuElement
接口,但它没有实现。
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
MenuSelectionManager
变化的菜单选择,如果需要转发,利用
MenuSelectionManager
的API。
注意:你不必转发事件到子组件。这是由MenuSelectionManager
自动完成。
processKeyEvent
接口
MenuElement
e
-
KeyEvent
path
-
MenuElement
路径阵列
manager
-
MenuSelectionManager
public void menuSelectionChanged(boolean isIncluded)
javax.swing.MenuElement
接口。覆盖
MenuElement.menuSelectionChanged
。
menuSelectionChanged
接口
MenuElement
isIncluded
-如果这个菜单是活动的,假如果不是
MenuElement.menuSelectionChanged(boolean)
public MenuElement[] getSubElements()
MenuElement
s数组。它将只返回符合
JMenuElement
接口项目。如果弹出式菜单
null
返回空数组。这种方法需要符合
MenuElement
接口。
getSubElements
接口
MenuElement
MenuElement
对象数组
MenuElement.getSubElements()
public Component getComponent()
JPopupMenu
组件。
getComponent
接口
MenuElement
JPopupMenu
对象
MenuElement.getComponent()
public boolean isPopupTrigger(MouseEvent e)
MouseEvent
被
JPopupMenu
目前安装界面弹出触发返回true。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.