Hi,
I have a problem with a Table using a CustomModel I have created.
The first time everything works fine, but whenever I re-create the Table and the user clicks on it, the content of the table changes into the old ones.
Here is a part of the code.
I cannot provide a SSCE for the moment, but I can give an idea of the whole thing.
private static void showResults() { // Creating JTable CustomTable Table = new CustomTable(); } public static class CustomTable extends JPanel { public CustomTable() { CustomTableModel TableModel = new CustomTableModel(); JTable Table = new JTable(TableModel); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(Table); Table.setFocusable(false); // Add the scroll pane to this frame Frame.add(scrollPane, BorderLayout.CENTER); scrollPane.setBounds(100, 300, 600, 250); } class CustomTableModel extends AbstractTableModel { private String rows[][] = Search(); private String headers[] = { "", "", "", "", ""}; public int getColumnCount() { return headers.length; } public int getRowCount() { return rows.length; } public String getColumnName(int col) { return headers[col]; } public Object getValueAt(int row, int col) { return rows[row][col]; } // Table not editable public boolean isCellEditable(int row, int col) { return false; } }
Basically I recreate the Table every time the user clicks on a button for searching. The results are correct but whenever I click on the table, the cell/row I click on changes its values on the first one.
I also tried to remove the possibility of selecting an item of the Table, but the problem still remains.
I also tried to remove it from the Frame (using Frame.remove(Table) ) and revalidate it. Also repaint and so on. Also tried to remove all the content of the Table before recreating a new one, but nothing...