|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPopupMenu
public class JPopupMenu
弹出菜单的实现,弹出菜单是一个可弹出并显示一系列选项的小窗口。JPopupMenu 用于用户在菜单栏上选择项时显示的菜单。它还用于当用户选择菜单项并激活它时显示的“右拉式 (pull-right)”菜单。最后,JPopupMenu 还可以在想让菜单显示的任何其他位置使用。例如,当用户在指定区域中右击时。
有关使用弹出菜单的示例和信息,请参阅 The Java Tutorial 中的 How to Use Menus。
警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy。
警告:此类的序列化对象与以后的 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.BaselineResizeBehavior, 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) 该工厂方法为添加到 JPopupMenu 的 Action 创建对应的 JMenuItem。 |
protected void |
firePopupMenuCanceled() 通知 PopupMenuListener 此弹出菜单将被取消。 |
protected void |
firePopupMenuWillBecomeInvisible() 通知 PopupMenuListener 此弹出菜单将变得不可见。 |
protected void |
firePopupMenuWillBecomeVisible() 通知 PopupMenuListener 此弹出菜单将变得可见。 |
AccessibleContext |
getAccessibleContext() 获取与此 JPopupMenu 关联的 AccessibleContext。 |
Component |
getComponent() 返回此 JPopupMenu 组件。 |
Component |
getComponentAtIndex(int i) 已过时。 由 Container.getComponent(int) 取代 |
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 属性重置为一个来自当前外观的值。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 构造方法详细信息 |
|---|
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()
JComponent 中的
updateUI
JComponent.updateUI()
public String getUIClassID()
JComponent 中的
getUIClassID
JComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)
protected void processFocusEvent(FocusEvent evt)
Component 复制的描述
FocusListener 对象。
如果组件上没有启用焦点事件,则不调用此方法。发生下列之一时启用焦点事件:
addFocusListener 注册了一个 FocusListener 对象。 enableEvents 启用了焦点事件。 如果为某个 Component 启用了焦点事件,则当前的 KeyboardFocusManager 确定是否应该将焦点事件指派到已注册的 FocusListener 对象。如果未指派事件,则 KeyboardFocusManager 调用 Component 的 dispatchEvent 方法,此方法又调用 Component 的 processFocusEvent 方法。
如果为 Component 启用了焦点事件,则用 FocusEvent 作为参数来调用 Component 的 dispatchEvent 方法将导致调用 Component 的 processFocusEvent 方法,而不管当前的 KeyboardFocusManager 如何。
注意,如果事件参数为 null,则未指定行为并且可能导致异常。
Component 中的
processFocusEvent
evt - 焦点事件
FocusEvent,
FocusListener,
KeyboardFocusManager,
Component.addFocusListener(java.awt.event.FocusListener),
Component.enableEvents(long),
Component.dispatchEvent(java.awt.AWTEvent)
protected void processKeyEvent(KeyEvent evt)
JComponent 中的
processKeyEvent
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(String s)
s - 要添加的菜单项的字符串
public JMenuItem add(Action a)
Action 对象的新菜单项添加到菜单的末尾。
a - 要添加到菜单的
Action
Action
protected JMenuItem createActionComponent(Action a)
JPopupMenu 的
Action 创建对应的
JMenuItem。
a - 要添加的菜单项的
Action
Action
protected PropertyChangeListener createActionChangeListener(JMenuItem b)
PropertyChangeListener,它在
Action 发生更改时更新控件。
public void remove(int pos)
Container 中的
remove
pos - 要移除的项的位置
IllegalArgumentException - 如果
pos 的值 < 0 或者
pos 的值大于项数
Container.add(java.awt.Component),
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 组成的数组。
PopupMenuListener,如果没有添加侦听器,则返回一个空数组
public void addMenuKeyListener(MenuKeyListener l)
MenuKeyListener 添加到弹出菜单。
l - 要添加的
MenuKeyListener
public void removeMenuKeyListener(MenuKeyListener l)
MenuKeyListener。
l - 要移除的
MenuKeyListener
public MenuKeyListener[] getMenuKeyListeners()
MenuKeyListener 组成的数组。
MenuKeyListener,如果没有添加侦听器,则返回一个空数组
protected void firePopupMenuWillBecomeVisible()
PopupMenuListener 此弹出菜单将变得可见。
protected void firePopupMenuWillBecomeInvisible()
PopupMenuListener 此弹出菜单将变得不可见。
protected void firePopupMenuCanceled()
PopupMenuListener 此弹出菜单将被取消。
public void pack()
public void setVisible(boolean b)
JComponent 中的
setVisible
b - 为 true 表示使弹出菜单可见,为 false 表示隐藏它
Component.isVisible()
public boolean isVisible()
Component 中的
isVisible
true;否则返回
false
Component.setVisible(boolean)
public void setLocation(int x,
int y)
Component 中的
setLocation
x - 屏幕坐标空间中弹出菜单的新位置的 X 坐标
y - 屏幕坐标空间中弹出菜单的新位置的 Y 坐标
Component.getLocation(),
Component.setBounds(int, int, int, int)
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 - 如果为 true,则绘制边框。
isBorderPainted()
protected void paintBorder(Graphics g)
borderPainted 属性为
true,则绘制弹出菜单的边框。
JComponent 中的
paintBorder
g -
Graphics 对象
JComponent.paint(java.awt.Graphics),
JComponent.setBorder(javax.swing.border.Border)
public Insets getMargin()
Insets 对象。
protected String paramString()
JPopupMenu 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为
null。
JComponent 中的
paramString
JPopupMenu 的字符串表示形式。
public AccessibleContext getAccessibleContext()
Accessible 中的
getAccessibleContext
JComponent 中的
getAccessibleContext
public void processMouseEvent(MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
MenuElement 接口,但它没有被实现。
MenuElement 中的
processMouseEvent
MenuElement.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)
public void processKeyEvent(KeyEvent e,
MenuElement[] path,
MenuSelectionManager manager)
MenuSelectionManager 的 API 处理从
MenuSelectionManager 转发的键事件并更改菜单选择。
注:不必将事件转发到子组件。此操作可以通过 MenuSelectionManager 自动完成。
MenuElement 中的
processKeyEvent
e -
KeyEvent
path -
MenuElement 路径数组
manager -
MenuSelectionManager
public void menuSelectionChanged(boolean isIncluded)
javax.swing.MenuElement 接口。重写
MenuElement.menuSelectionChanged。
MenuElement 中的
menuSelectionChanged
isIncluded - 如果此菜单处于激活状态,则为 true;如果不是,则为 false
MenuElement.menuSelectionChanged(boolean)
public MenuElement[] getSubElements()
MenuElement 组成的数组,包含此菜单组件的子菜单。它将只返回遵守
JMenuElement 接口的项。如果弹出菜单为
null,则返回空数组。要求此方法遵守
MenuElement 接口。
MenuElement 中的
getSubElements
MenuElement 对象的数组
MenuElement.getSubElements()
public Component getComponent()
JPopupMenu 组件。
MenuElement 中的
getComponent
JPopupMenu 对象
MenuElement.getComponent()
public boolean isPopupTrigger(MouseEvent e)
JPopupMenu 的当前安装 UI 将
MouseEvent 视为弹出菜单触发器,则返回 true。
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。