My table has 4 columns, and I only want column 1 to be allowed to be clicked. Also, this code also allows the LEFT mouse button to be used, I only want the RIGHT button.
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int iCol = jTable1.getSelectedColumn();
if(iCol == 1 && evt.getModifiers() == InputEvent.BUTTON3_MASK)
{
if(evt.getClickCount() == 2)
{
int iRow = jTable1.getSelectedRow();
File iFile = new File(jTable1.getValueAt(iRow, iCol).toString());
String iPath = iFile.getAbsolutePath();
File iDir = new File(iPath.substring(0, iPath.lastIndexOf(File.separator)));
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(iDir);
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
I’m sorry if this question turned out as 2.
Concerning the clicking only of a specific column:
1. create the table using you own model.
2. create the new model overriding the function you need (i.e. isCellEditable)