我有一个JTable
我想左键单击并右键单击JPopupMenu
它。通常通过左键单击 JTable,您可以选择一行。我想通过右键单击并显示弹出菜单来做同样的事情。
有人知道怎么做这个吗?
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
//this line gives wrong result because table.getSelectedRow() stay alwase on the same value
codeModel.setSelectedFileName(table.getValueAt(table.getSelectedRow(), 0).toString());
JPopupMenu popup = createRightClickPopUp();
popup.show(e.getComponent(), e.getX(), e.getY());
}else{
codeModel.setSelectedFileName(table.getValueAt(table.getSelectedRow(), 0).toString());
codeTextArea.setText(codeModel.getCodeContents());
}
}
});