In you need to set the selection properties of your table to true, like below. You also have to make sure that the isCellEditable
method is overridden and set to false, the AbstractTableModel
class does this by default.
final JTable table = new JTable(new AbstractTableModel() {
@Override
public Object getValueAt(int r, int c) {
return data[r][c];
}
@Override
public int getRowCount() {
return data.length;
}
@Override
public int getColumnCount() {
return data[1].length;
}
});
table.setRowSelectionAllowed(true);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
This will allow the cell to be highlight individually and copied from but will not allow editing of the cell.
EDIT: Changed answer!