博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JPopupMenu_1
阅读量:5264 次
发布时间:2019-06-14

本文共 2081 字,大约阅读时间需要 6 分钟。

package com.han;import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;public class JPopupMenu_1 extends JFrame {	/**	 * 	 */	private static final long serialVersionUID = 2924353502687938030L;	public JPopupMenu_1() {		// TODO Auto-generated constructor stub		final JPopupMenu popupMenu = new JPopupMenu();		JMenuItem menuItem1 = new JMenuItem("剪切");		JMenuItem menuItem2 = new JMenuItem("复制");		JMenuItem menuItem3 = new JMenuItem("粘贴");		JMenu menuSub = new JMenu ("编辑");		JMenuItem menuSubItem1 = new JMenuItem("只读");		JMenuItem menuSubItem2 = new JMenuItem("可写");		JMenu menuSubSub = new JMenu("字体");		menuSub.add(menuSubItem1);		menuSub.add(menuSubItem2);		menuSub.add(menuSubSub);		JMenuItem menuSubSubItem1 = new JMenuItem("加粗");		JMenuItem menuSubSubItem2 = new JMenuItem("倾斜");		menuSubSub.add(menuSubSubItem1);		menuSubSub.add(menuSubSubItem2);				popupMenu.add(menuItem1);		popupMenu.add(menuItem2);		popupMenu.add(menuItem3);		popupMenu.add(menuSub);				JLabel label = new JLabel("请在这里单击鼠标右键!");				Container container = getContentPane();		container.add(label, BorderLayout.CENTER);				// MouseAdapter (abstract class) is different from 		// the MouseListener (interface). The interest of the abstract class		// is that we need not to override all the methods declared in 		// the corresponding interface.		container.addMouseListener(new MouseAdapter() { 			public void mouseReleased(MouseEvent e) {				if (e.isPopupTrigger()) {					popupMenu.show(e.getComponent(), e.getX(), e.getY());					}			}					});	}	/**	 * @param args	 */	public static void main(String[] args) {		// TODO Auto-generated method stub		JPopupMenu_1 frame = new JPopupMenu_1();		frame.setTitle("创建弹出式菜单");		frame.setVisible(true);		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		frame.setBounds(100, 100, 400, 300);	}}

转载于:https://www.cnblogs.com/java0721/archive/2012/05/28/2602473.html

你可能感兴趣的文章
bugku 变量
查看>>
Python 环境傻瓜式搭建 :Anaconda概述
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>
CF1215E Marbles
查看>>
.net Core 图片验证码 基于SkiaSharp实现
查看>>
fish redux 个人理解
查看>>
java 笔记一些
查看>>
BZOJ2339 HNOI2011卡农(动态规划+组合数学)
查看>>
BZOJ3811 玛里苟斯(线性基+概率期望)
查看>>
简单的异步函数async/await例子
查看>>
一个点击事件引发的案件
查看>>
Android.mk介绍
查看>>
json 字符串转成对象
查看>>
octave基本操作
查看>>