Java中的JPopupMenu 的概念

public class JPopupMenu extends JComponent implements Accessible,MenuElement

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

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

警告:Swing 不是线程安全的。有关更多信息,请参阅Swing's Threading Policy。

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

嵌套类摘要
protected  classJPopupMenu.AccessibleJPopupMenu
          此类实现 JPopupMenu 类的可访问性支持。
static classJPopupMenu.Separator
          弹出与菜单有关的分隔符。

从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer

从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
构造方法摘要
JPopupMenu()
          构造一个不带“调用者”的 JPopupMenu
JPopupMenu(String label)
          构造一个具有指定标题的 JPopupMenu
方法摘要
 JMenuItemadd(Action a)
          将指派指定 Action 对象的新菜单项添加到菜单的末尾。
 JMenuItemadd(JMenuItem menuItem)
          将指定菜单项添加到此菜单的末尾。
 JMenuItemadd(String s)
          创建具有指定文本的菜单项,并将其添加到此菜单的末尾。
 voidaddMenuKeyListener(MenuKeyListener l)
          将 MenuKeyListener 添加到弹出菜单。
 voidaddPopupMenuListener(PopupMenuListener l)
          添加 PopupMenu 侦听器。
 voidaddSeparator()
          将新分隔符添加到菜单的末尾。
protected  PropertyChangeListenercreateActionChangeListener(JMenuItem b)
          返回一个正确配置的 PropertyChangeListener,它在 Action 发生更改时更新控件。
protected  JMenuItemcreateActionComponent(Action a)
          该工厂方法为添加到 JPopupMenuAction 创建对应的 JMenuItem
protected  voidfirePopupMenuCanceled()
          通知 PopupMenuListener 此弹出菜单将被取消。
protected  voidfirePopupMenuWillBecomeInvisible()
          通知 PopupMenuListener 此弹出菜单将变得不可见。
protected  voidfirePopupMenuWillBecomeVisible()
          通知 PopupMenuListener 此弹出菜单将变得可见。
 AccessibleContextgetAccessibleContext()
          获取与此 JPopupMenu 关联的 AccessibleContext。
 ComponentgetComponent()
          返回此 JPopupMenu 组件。
 ComponentgetComponentAtIndex(int i)
          已过时。 Container.getComponent(int) 取代
 intgetComponentIndex(Component c)
          返回指定组件的索引。
static booleangetDefaultLightWeightPopupEnabled()
          获取 defaultLightWeightPopupEnabled 属性,默认情况下,该属性为 true
 ComponentgetInvoker()
          返回作为此弹出菜单的“调用者”的组件。
 StringgetLabel()
          返回弹出菜单的标签。
 InsetsgetMargin()
          返回弹出菜单的边框与其包含内容之间的空白(以像素表示)。
 MenuKeyListener[]getMenuKeyListeners()
          返回利用 addMenuKeyListener() 添加到此 JPopupMenu 的所有 MenuKeyListener 组成的数组。
 PopupMenuListener[]getPopupMenuListeners()
          返回利用 addPopupMenuListener() 添加到此 JMenuItem 的所有 PopupMenuListener 组成的数组。
 SingleSelectionModelgetSelectionModel()
          返回处理单个选择的模型对象。
 MenuElement[]getSubElements()
          返回 MenuElement 组成的数组,包含此菜单组件的子菜单。
 PopupMenuUIgetUI()
          返回用于呈现此组件的外观 (L&F) 对象。
 StringgetUIClassID()
          返回用于呈现此组件的 L&F 类名。
 voidinsert(Action a, int index)
          在给定位置插入指定 Action 对象的菜单项。
 voidinsert(Component component, int index)
          将指定组件插入到菜单的给定位置。
 booleanisBorderPainted()
          检查是否应该绘制边框。
 booleanisLightWeightPopupEnabled()
          获取 lightWeightPopupEnabled 属性。
 booleanisPopupTrigger(MouseEvent e)
          如果 JPopupMenu 的当前安装 UI 将 MouseEvent 视为弹出菜单触发器,则返回 true。
 booleanisVisible()
          如果弹出菜单可见(当前显示的),则返回 true。
 voidmenuSelectionChanged(boolean isIncluded)
          当菜单栏选择发生更改以激活或取消激活此菜单时传递消息。
 voidpack()
          布置容器,让它使用显示其内容所需的最小空间。
protected  voidpaintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制弹出菜单的边框。
protected  StringparamString()
          返回此 JPopupMenu 的字符串表示形式。
protected  voidprocessFocusEvent(FocusEvent evt)
          处理组件上发生的焦点事件,方法是将其指派到任意已注册的 FocusListener 对象。
protected  voidprocessKeyEvent(KeyEvent evt)
          处理快捷键事件,如助记符和加速器。
 voidprocessKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
          如有必要,通过使用 MenuSelectionManager 的 API 处理从 MenuSelectionManager 转发的键事件并更改菜单选择。
 voidprocessMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
          要求此方法遵守 MenuElement 接口,但它没有被实现。
 voidremove(int pos)
          从此弹出菜单移除指定索引处的组件。
 voidremoveMenuKeyListener(MenuKeyListener l)
          从弹出菜单移除 MenuKeyListener
 voidremovePopupMenuListener(PopupMenuListener l)
          移除 PopupMenu 侦听器。
 voidsetBorderPainted(boolean b)
          设置是否应该绘制边框。
static voidsetDefaultLightWeightPopupEnabled(boolean aFlag)
          设置 lightWeightPopupEnabled 属性的默认值。
 voidsetInvoker(Component invoker)
          设置此弹出菜单的调用者,即弹出菜单在其中显示的组件。
 voidsetLabel(String label)
          设置弹出菜单的标签。
 voidsetLightWeightPopupEnabled(boolean aFlag)
          设置 lightWeightPopupEnabled 属性的值,默认情况下该值为 true
 voidsetLocation(int x, int y)
          使用 X、Y 坐标设置弹出菜单的左上角的位置。
 voidsetPopupSize(Dimension d)
          使用 Dimension 对象设置弹出窗口的大小。
 voidsetPopupSize(int width, int height)
          将弹出窗口的大小设置为指定的宽度和高度。
 voidsetSelected(Component sel)
          设置当前选择的组件,此方法将更改选择模型。
 voidsetSelectionModel(SingleSelectionModel model)
          设置处理单个选择的模型对象。
 voidsetUI(PopupMenuUI ui)
          设置呈现此组件的 L&F 对象。
 voidsetVisible(boolean b)
          设置弹出菜单的可见性。
 voidshow(Component invoker, int x, int y)
          在组件调用者的坐标空间中的位置 X、Y 显示弹出菜单。
 voidupdateUI()
          将 UI 属性重置为一个来自当前外观的值。



 

 

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李逍遥~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值