Hi,
Please help me out. My problem is, As per the current implementation of my application, when I Right Click on a JTable Row, A Popup menu appears to give me an option to "delete" the row. On "delete" JMenuItem -> I want only left mouse click should work and if someone presses left click or any othe button, it shud not react and the popup menu should remain as it is.
I tried to acheive this with MouseListener but when user clicks any other button then "left" operation doesn't happen but at the same time menu also disappears.
So Currently I am using ActionListenr on JMenuItem.
JPopupMenu popup = new JPopupMenu();
JMenuItem headItem = new JMenuItem("Permission Value");
popup.add(headItem);
popup.addSeparator();
JMenuItem menuItem = new JMenuItem("Delete: " + permissionTypeValueEntity.getValueAt(0));
popup.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try {
String valueToDelete = permissionTypeValueEntity.getValueAt(0);
permissionTypeActionListener.deletePermissionTypeValue(valueToDelete);
model.removeEntity(permissionTypeValueEntity);
int indexToNext = table.getRowCount()-1;
// Once a value is deleted, immediate previous value should become the selected one.
permissionTypeActionListener.setSelectedPermissionValueIndex(indexToNext);
permissionTypeActionListener.loadPermissionTypeValues(permissionTypeActionListener.getSelectedPermissionType());
table.scrollRowToVisible(indexToNext);
}
catch (PermissionServiceException pse) {
MessageDialog dialog = MessageDialog.createInstance(PermissionValueListPanel.this, true);
dialog.showErrorMessage("User Message", pse.getMessage());
}
}
});
popup.show(e.getComponent(), e.getX(), e.getY());