当前位置: 代码迷 >> J2SE >> 如何在List中添加JPopupMenu
  详细解决方案

如何在List中添加JPopupMenu

热度:969   发布时间:2016-04-24 18:14:05.0
怎么在List中添加JPopupMenu?
添加了但是显示不了,很奇怪?

------解决方案--------------------
jTable1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(e.getButton()==3){
showMenu(e.getX(),e.getY());
}
}
});
protected void showMenu(int x,int y) {
JPopupMenu popup=new JPopupMenu();
JMenuItem jItem2=new JMenuItem("增加");
JMenuItem jItem3=new JMenuItem("修改");
JMenuItem jItem4=new JMenuItem("删除");
popup.add(jItem2);
popup.add(jItem3);
popup.add(jItem4);
popup.show(jTable1,x,y);
}
  相关解决方案