I have seen quite a few threads on refreshing a JTable using:
String[] columnNames = {"column1","column2,......,"columnN"};
String[][] tableData = new String[1][columnNames.length];
JTable table = new JTable(tableData,columnNames);
JScrollPane scrollpane = new JScrollPane(table);
contentPane.add(scrollpane);
... make a change to the data stored in tableData
then call...
AbstractTableModel model = (AbstractTableModel) table.getModel();
model.fireTableDataChanged();
But this doesn't seem to change anything for me. I need to initially show display a blank table with one row and then update it when the user loads a data file however the code below doesn't seem to work for me. I assume its because im redefining tableData
but this has to be done as i do not know how many rows of data are to be displayed until the user loads a file. How can I update the table?
Edit: To make it clearer the code i am running is:
//Initialize Table With 1 Blank Row
String[] columnNames = {"column1","column2,......,"columnN"};
String[][] tableData = new String[1][columnNames.length];
JTable table = new JTable(tableData,columnNames);
JScrollPane scrollpane = new JScrollPane(table);
contentPane.add(scrollpane);
//When the file is loaded resize tableData so it can fit all the file data
tableData = new String[length of data file][columnNames.length];
//Update some of the tableData points
tableData[0][0]="data 1";
tableData[1][0]="data 2";
tableData[0][1]="data 3";
tableData[1][1]="data 4";
....etc
//Tell the JTable to update
AbstractTableModel model = (AbstractTableModel) table.getModel();
model.fireTableDataChanged();