@Sniper is not the answer, but I can not resist, because your code is very complicated, incorrect, miss the extra weight there, necessary for ...
Invalid key element is overriding TableModel.getColumnClass (), this is necessary to sort the table for the function
import java.awt.*; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import static javax.swing.JFrame.EXIT_ON_CLOSE; import javax.swing.table.*; public class TableBasic { private JFrame frame = new JFrame(); private String[] columnNames = {"Date", "String", "Long", "Boolean"}; private Object[][] data = { {getJavaDate("13-11-2020"), "A", new Double(1), Boolean.TRUE}, {getJavaDate("13-11-2018"), "B", new Double(2), Boolean.FALSE}, {getJavaDate("12-11-2015"), "C", new Double(9), Boolean.TRUE}, {getJavaDate("12-11-2015"), "D", new Double(4), Boolean.FALSE} }; private DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); } }; private JTable table = new JTable(model); private JScrollPane scrollPane = new JScrollPane(table); private static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy"); public TableBasic() { table.setPreferredScrollableViewportSize(table.getPreferredSize()); table.setAutoCreateRowSorter(true); setRenderers();
source share