I want a different popup on each row of JTable. So I thought of setting the row on right click and then add popmenu to JTable. The following code will help you'll to understand the problem...
private synchronized void HandlePopup(java.awt.event.MouseEvent evt) {
jTable1.setComponentPopupMenu(null);
if(evt.getButton()==MouseEvent.BUTTON3){
int y = evt.getY();
int row = Math.round(y / jTable1.getRowHeight());
jTable1.setRowSelectionInterval(row, row);
System.out.println("Row Selected = " + row);
jTable1.setComponentPopupMenu(popupMenu);
}
else jTable1.setComponentPopupMenu(null);
}
private void CreatePopup() {
// Create popup menu, attach popup menu listener
popupMenu = new JPopupMenu("Title");
// Cut
JMenuItem cutMenuItem = new JMenuItem("Cut");
popupMenu.add(cutMenuItem);
// Copy
JMenuItem copyMenuItem = new JMenuItem("Copy");
popupMenu.add(copyMenuItem);
// Paste
JMenuItem pasteMenuItem = new JMenuItem("Paste");
pasteMenuItem.setEnabled(false);
popupMenu.add(pasteMenuItem);
// Separator
popupMenu.addSeparator();
// Find
JMenuItem findMenuItem = new JMenuItem("Find");
popupMenu.add(findMenuItem);
}
:) Here for the first right click the row gets selected.... then only the popup works and then there is no row selection. the pop is always the same...coz new row gets never selected... So how can I handle both popup with right selection...??? Please help me with this...