Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

jTable selectedRowIndex at mouse click

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}

}
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic