I observed one thing about my right click on the JTable.
If I right click on a row. it shows my popUpMenu item.
But now if I right click on another row, I must
right click 2 times on the other row before my Jpopup appears.
Is that any way to make it smoother as in I only need to right click one time on
another row?

table.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
                    System.out.println("Right Click");
                    int r = table.rowAtPoint(e.getPoint());
                    if (r >= 0 && r < table.getRowCount()) {
                        table.setRowSelectionInterval(r, r);

                    } else {

                    int rowindex = table.getSelectedRow();
                    if (rowindex < 0)
                    if (e.isPopupTrigger() && e.getComponent() instanceof JTable ) {
                        item = popupMenu.add("itemOne");
                        popupMenu.show(e.getComponent(), e.getX(), e.getY());

My guess would be the line where you reset/clear the current selected row but not set the new selected row again. As a result, the first click goes into Line 8. The next click on another row goes into Line 11 which in turn is returned to the caller in Line 16. Just a guess from the behavior you explained...

This article has been dead for over six months. Start a new discussion instead.