java程序如何添加鼠标右键功能,使右键点击到某个item时,使显示的菜单里面包含删除等功能,像QQ一样~~~
1个回答
展开全部
这是我在一个JTable中单击又键弹出的popmenu的部分代码;
programTable.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
showPopup(e);
}
public void mouseReleased(MouseEvent e) {
showPopup(e);
}
private void showPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
int selRow = programTable.rowAtPoint(e.getPoint());
programTable.setRowSelectionInterval(selRow, selRow);
}
}
});
programTable.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
showPopup(e);
}
public void mouseReleased(MouseEvent e) {
showPopup(e);
}
private void showPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
int selRow = programTable.rowAtPoint(e.getPoint());
programTable.setRowSelectionInterval(selRow, selRow);
}
}
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询