e813. 获得当前选择的菜单或菜单项
The currently selected menu or menu item in a JMenu
or JPopupMenu
is tracked by MenuSelectionManager
and can be retrieved by calling MenuSelectionManager.getSelectedPath()
. This method returns an array of MenuElement
objects, representing all the menu objects that are part of the selected menu or menu item. For example, when a menu is opened in a menu bar, the sequence of elements in the path is: JMenuBar
, JMenu
, and JPopupMenu
. If a menu item in the open menu is then selected, there will be fourth element, a JMenuItem
.
The menu path also includes nested menus. For example, if the currently selected menu item is part of a nested menu in a menu bar, the sequence of elements is: JMenuBar
, JMenu
, JPopupMenu
, JMenu
, JPopupMenu
, and JMenuItem
. Note that a JMenu
is always followed by a JPopupMenu
.
If a menu item in a popup menu is selected, the sequence of menu objects is simply JPopupMenu
and JMenuItem
. If the menu item is part of a nest menu, the sequence is, JPopupMenu
, JMenu
, JPopupMenu
, and JMenuItem
.
// Get the selected menu path
MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); if (path.length == 0) {
// No menus are opened or menu items selected
} // Retrieve the labels of all the menu elements in the path
for (int i=0; i<path.length; i++) {
Component c = path[i].getComponent(); if (c instanceof JMenuItem) {
JMenuItem mi = (JMenuItem)c;
String label = mi.getText();
// Note: JMenu is a subclass of JMenuItem; also JMenuBar does not have a label
}
}
Related Examples |
e813. 获得当前选择的菜单或菜单项的更多相关文章
- e815. 监听当前选择的的菜单或菜单项
The currently selected menu or menu item in a JMenu or JPopupMenu is tracked by MenuSelectionManager ...
- 13、Java菜单条、菜单、菜单项
13.Java菜单条.菜单.菜单项 一般用Java做界面时,都得牵涉到菜单条.菜单.菜单项的设计.菜单项放在菜单里,菜单放在菜单条里,且其字体均可设置. 13.1.菜单条(Menubar) Frame ...
- 在Unity3d编辑器中加入菜单以及菜单项
在引用UZGUI插件时,u3d编辑器的菜单条发生了变化,新增了菜单和菜单项,于是乎自己也像尝试一下,看了EZGUI的About_EZ_GUI脚本文件后,结果大出我所料,原来SO EASY! using ...
- java学习:AWT组件和事件处理的笔记(1)--菜单条,菜单,菜单项
菜单放在菜单条里,菜单项放在菜单里1.MenuBar 在java.awt包中,负责创建菜单条,即MenuBar的一个实例,便是一个菜单条. 在Frame类中的setMenuBar(Menu ...
- 为Windows资源管理器右键菜单添加菜单项
为Windows资源管理器右键菜单添加菜单项 在Windows下命令行用的比较多,经常在资源管理器里翻到某个目录,若想要在此目录下跑命令,只能是打开cmd.exe,然后一路cd才能到达此目录. 每次都 ...
- e808. 建立菜单栏,菜单,菜单项
When the user selects a menu item, it fires an action event. // Create the menu bar JMenuBar menuBar ...
- e814. 创建一个可监听选择状态的菜单项
A menu item can receive notification of selection changes by overriding its menuSelectionChanged() m ...
- GUI tkinter (Menu)菜单项篇
"""添加顶层菜单:1.我们可以使用Menu类来新建一个菜单,Menu和其他的组件一样,第一个是parent,这里通常可以为窗口2.然后我们可以用add_command方 ...
- 在Winform界面菜单中实现动态增加【最近使用的文件】菜单项
在我们一些和文件处理打交道的系统中,我们往往需要记录下最近使用的文件,这样方便用户快速打开之前浏览或者编辑过的文件,这种在很多软件上很常见,本文主要介绍在Winform界面菜单中实现[最近使用的文件] ...
随机推荐
- MySQL Workbench 的安全设置
今日用MySQL Workbench进行数据库的管理更新时,执行一个更新的语句碰到以下错误提示: Error Code: 1175 You are using safe update mode and ...
- Vue.js简介及指令
1.Vue.js的特点 Vue.js是一个Javascript MVVM(Model-View-ViewModel)库,与传统Jquery的区别在于,Vue.js舍弃了繁杂的DOM操作, 如取DOM值 ...
- 【硅谷问道】 WWDC 17: 开发者的最初观感
[硅谷问道] WWDC 17: 开发者的最初观感 前言 每年的 WWDC 都是 iOS 开发者集体高潮的时刻.第一天的 WWDC 带来了全新的 iOS 11.MacOS.tvOS 和 watchOS, ...
- 使用 CocoaPods 给微信集成 SDK 打印收发消息
使用 CocoaPods 给微信集成 SDK 打印收发消息 推荐序 本文介绍的是一套逆向工具,可以在非越狱手机上给任意应用增加插件.在文末的示例中,作者拿微信举例,展示出在微信中打印收发消息的功能. ...
- vs ComboBox显示多行
ComboBox,Drop List Type添加了多个数据,但是编译出来点下来按钮,只有一行. 惆怅 然后搜了下发现有人说: 在资源里面点向下箭头,把数据区拉长一点 然后才发现,原来资源里的Comb ...
- adb install使用说明
[时间:2016-08] [状态:Open] [关键词:android, apk,adb install] 将apk安装到模拟器或者手机上. Pushes an Android application ...
- css超出一行添加省略号属性:text-overflow和white-space
通过使用text-overflow和white-space属性来使文本在一行内显示,超出则加省略号,添加如下html代码: <p>前端开发博客专注前端开发和技术分享,如果描述超过100像素 ...
- Eigen教程(8)
整理下Eigen库的教程,参考:http://eigen.tuxfamily.org/dox/index.html 原生缓存的接口:Map类 这篇将解释Eigen如何与原生raw C/C++ 数组混合 ...
- myeclipse之SSH整合图文详解
首先搭建开发环境 打开MyEclipse,新建一个web project ,然后右击项目执行如下步骤: 开启服务器无错误即搭建成功,整合后项目目录: 另附上SSH所必须的开发包:
- C#中的索引器
在Java中,一般会这样使用get,set方法: class Person{ private String name; public void setName(String name){ this.n ...