I have created a table in java in Netbeans and filled it with some data. Now I want to show some detail in a text area corresponding to the particular column in a row when I click on that cell. How can I find out using event listener that on which cell user has clicked.
Find the location of the click event and get the cell you are searching for:
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = jTable1.rowAtPoint(evt.getPoint());
int col = jTable1.columnAtPoint(evt.getPoint());
if (row >= 0 && col >= 0) {
......
}
}
});
JTable can listnening for selected TableCell (by mouseclick or from keyboard),you have to look for implemets ListSelectionListener, examples here or here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With