The moose likes Swing / AWT / SWT and the fly likes JTable - selection of a right-click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable - selection of a right-click" Watch "JTable - selection of a right-click" New topic

JTable - selection of a right-click

Amit Rosner

Joined: Dec 03, 2001
Posts: 22
I want to be able to select a JTable row on a mouse right-click, just as it happens on a mouse left-click, for opening a popup menu. Opening the menu itself is no problem. The problem is that the row is not selected.
How can I do that?
lavanya subramanian
Ranch Hand

Joined: Nov 03, 2000
Posts: 52
Hi Amit,
try this code and i think this might help you,
table1.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent me)
if(SwingUtilities.isRightMouseButton(me) == true)
int row = table1.rowAtPoint(me.getPoint());

//your popup menu goes here.
try and let me know,
I agree. Here's the link:
subject: JTable - selection of a right-click
It's not a secret anymore!