JAVA GUI学习 - JPopupMenu鼠标右键菜单组件学习
public class JPopmenuKnow { public void test() { //为表格添加鼠标右键菜单 JMenuItem jMenuItemFileInfo = new JMenuItem("文件属性");jMenuItemFileInfo.setName("jMenuItemFileInfo"); JMenuItem jMenuItemOpenFile = new JMenuItem("打开文件");jMenuItemOpenFile.setName("jMenuItemOpenFile"); JPopupMenu jPopupMenuFileInfo = new JPopupMenu(); jPopupMenuFileInfo.add(jMenuItemFileInfo);jPopupMenuFileInfo.add(jMenuItemOpenFile); JTable jTableFiles = new JTable(); jTableFiles.setComponentPopupMenu(jPopupMenuFileInfo); //添加监听器 JPopmenuActionListener jPopmenuActionListener = new JPopmenuActionListener(); jMenuItemFileInfo.addActionListener(jPopmenuActionListener); jMenuItemOpenFile.addActionListener(jPopmenuActionListener); } private class JPopmenuActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { } } }