Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jTable selectedRowIndex at mouse click  RSS feed

 
mona anshita
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ...

m using Jtable..in my application i want to get the selected row index
i have method getSelectedRow() but i want selected row index at click on
popup menu's iteam.meaning there is a popup menu on right click at jtable
having a pop up menu iteam deleteRow wen user click on this item i want to
get the index of selected row to delete selected row.
please friends give me solution.

thanx in advance
monaanshita
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a MouseListener for the JComponent that calls the JPopupMenu. Then use something like javax.swing.SwingUtilities.convertPointToScreen() to convert the MouseEvent.getPoint() to screen X/Y for the JPopupMenu.
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) {
tableMouseReleased(evt);
}
});


private void tableMouseReleased{

int row = table.rowAtPoint(evt.getPoint());//better than getSelectedRow()

table.getSelectionModel().setSelectionInterval(row,row);//Sets the row to a selected state.

if(evt.isPopupTrigger()) {
int xc = evt.getX();
int yc = evt.getY();
popupmenu.show(evt.getComponent(), evt.getX(), evt.getY());
}

}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!