wood burning stoves 2.0*
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
Author

JTable - selection of a right-click

Amit Rosner
Greenhorn

Joined: Dec 03, 2001
Posts: 22
Hi!
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?
Amit.
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());

table1.clearSelection();
table1.addRowSelectionInterval(row,row);
//your popup menu goes here.
}
}
});
try and let me know,
regards,
lavanya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable - selection of a right-click