I've been trying to get my action listener to select the row where my mouse right clicks. I referred alot of posts and these are some of them:
Heres my code:
t1 is the name of the table
public void clickListener(){
final RowPopUp pops = new RowPopUp(jTable1);
jTable1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
if(SwingUtilities.isRightMouseButton(me)){
int row = jTable1.rowAtPoint( me.getPoint() );
jTable1.changeSelection( row, 0, false, false );
pops.getRow(jTable1.getSelectedRow());
pops.show(me.getComponent(),me.getX(),me.getY());
}
}
});
}
now heres what happens.
when I right click on my table with no selected row, I get a Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
error however, when there is an existing selected row on my table, the code works and chooses on the row I right click into.
what I want to achieve is when I right click anywhere on the rows even if there is no selected row, the part I right click into will be selected. any ideas how will this work?