I have a JFrame
which holds a JXTable
(from SwingX dependency) and a JButton
.
Once I click the JButton the table should get updated each time. In my case it gets updated only at the first time. Other events also get triggered on the button click (which happens each time I click the button). Only the table is not refreshed with the new rows added.
I am using DeafultTableModel
and have tried (explicit trigger) all suggested methods like repaint
, fireTableDataChanged
etc.
Can someone please help?
EDIT-1 (code snippet added): -
// the actions will take place when VALIDATE button is clicked
validateButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent ae) {
if (evCheckbox1.isSelected() || !list.isSelectionEmpty()) {
try {
// store the validation errors for future use
List<List<String>> validationErrors = validateSheet(Driver.this.fileLocation, list
.getSelectedValuesList(), regulatorTypeCB.getSelectedItem().toString(), sheetTypeCB
.getSelectedItem().toString());
// creates the validation error overview to be added to roTable
Map<String, Integer> tmpMap = getValidationErrorsOverview(validationErrors);
System.out.println(tmpMap);
// create the report overview table
String[] columnNames = {"SHEET_NAME", "VALIDATION_NAME", "#"};
DefaultTableModel tmodel = new DefaultTableModel(0, 0);
tmodel.setColumnIdentifiers(columnNames);
JXTable roTable = new JXTable();
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
roTable.addHighlighter(HighlighterFactory.createSimpleStriping());
List<String> tlist = new ArrayList<String>();
JScrollPane scrPane = new JScrollPane(roTable);
scrPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
overviewPanel.add(scrPane);
// create a list from the validation error overview map to insert as a row in table
for (Map.Entry<String, Integer> entry : tmpMap.entrySet()) {
tlist.add(entry.getKey().split(":")[0]);
tlist.add(entry.getKey().split(":")[1]);
tlist.add(String.valueOf(entry.getValue()));
}
// add rows in table
for (int i = 0; i < tmpMap.size(); i++) {
tmodel.addRow(new Object[] {tlist.get((i * 3) + 0), tlist.get((i * 3) + 1),
tlist.get((i * 3) + 2)});
}
FileUtils.writeStringToFile(logFile, "\n" + new Date().toString() + "\n", true);
roTable.setModel(tmodel);
roTable.repaint();
// frame refresh
Driver.this.frame.revalidate();
Driver.this.frame.repaint();
// open the log file in notepad.exe
ProcessBuilder pb = new ProcessBuilder("Notepad.exe", "verifier.log");
pb.start();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});