I'm a kind of new in Java programming, and today I faced a problem.
What the problematic part of the program should do is essentially described by the following steps:
- Do a query
- Fill a jTable with the result of the query
- Apply a rowsorter to the jtable
- Make the cells of the jTable not editable but clickable
I've found a solution on the Internet, but I don't really know how to implement it.
The solution should be, if I didn't misunderstand, overriding the isCellEditable
method of the DefaultTableModel
associated to the table so it will always return false.
This is the code that does the steps above described:
ResultSet rs = CheckList.dbConnection.genericQuery(query);
if (rs != null) {
jTable1.setRowSorter(null); \\STEP 1
jTable1.setModel(resultSetToTableModel(rs)); \\STEP 2
DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); \\STEP 3
TableRowSorter <DefaultTableModel> sorter = new TableRowSorter(model); \\STEP 3
jTable1.setRowSorter(sorter); \\STEP 3
}
With this said, how can I implement the overriding of the method? Obviously if you find something wrong in the code, feel free to fix it, I'm here to learn! :P
Vincenzo