//...where instance variables are declared:
JPopupMenu popup;
//...where the GUI is constructed:
//Create the popup menu.
popup = new JPopupMenu();
menuItem = new JMenuItem("A popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Another popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);
//Add listener to components that can bring up popup menus.
MouseListener popupListener = new PopupListener();
output.addMouseListener(popupListener);
menuBar.addMouseListener(popupListener);
...
class PopupListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(),
e.getX(), e.getY());
}
}
}
分享到:
相关推荐
高级弹出菜单高级弹出菜单高级弹出菜单高级弹出菜单高级弹出菜单高级弹出菜单
MFC制作右键弹出菜单
通过点击Qt中的pushbutton,可以弹出菜单,菜单选项是QAction,可以连接槽完成相应功能。Qt工程是基于Qt5.10.1 32位,Qt Creator 4.5.1(Community)
jquery弹出菜单 jquery 弹出菜单 jquery弹出菜单 jquery 弹出菜单 jquery弹出菜单 jquery 弹出菜单
点击标签栏弹出菜单,并且出现透明遮罩; 遮罩优先级在弹出框之下; 弹出框内标签的设置; 滚动栏滚动条的隐藏 如何解决? 弹性布局,横向,三者平分整栏; 状态监听点击事件,数据控制hide或者show,通过rgba...
Qt5实现的使用鼠标右击即可在相应位置出现一个弹出菜单
Android 按Menu弹出菜单,九宫格样式。
Flutter高阶技术:如何实现自定义弹出菜单框
jQuery适用于手机端底部弹出菜单列表代码 jQuery适用于手机端底部弹出菜单列表代码
1.支持展开折叠的弹出菜单的实现思路: 1.1将弹出视图添加到keyWindow,蒙版也添加到主窗口(主要原因是点击屏幕的空白处,需要隐藏弹出视图) 1.2展示的时候,动画从右上角往左下脚延伸;隐藏的时候,动画从左下脚往...
android 底部弹出菜单(带透明背景)
通过使用javascript制作弹出菜单
js固定区块右键弹出菜单代码是一款点击鼠标右键弹出菜单选择效果代码。
弹出菜单,类似苹果小白点,点击收缩和弹出,不占用多余空间
在TreeView上点击右键弹出菜单,同时鼠标点击处的TreeViewItem被选中,然后我们针对选中的数据进行处理。 不过,WPF的TreeView并没有提供右键单击选中的功能。我们需要自己去实现。 【思路】 最基本的思路是,在...
仿QQ顶部弹出菜单,居中弹出菜单,底部弹出菜单,以及指定位置弹出,非常好用
仿QQ空间底部弹出菜单,具体实现原理是PopupWindow
仿京东商城左侧商品展示的浮动层弹出菜单。
在网页中自定义右击弹出菜单.在网页中自定义右击弹出菜单.
重新绘制弹出菜单,改变系统默认的弹出菜单样式