I am currently trying to get my program to input data from a user-defined CSV file into a JTable. However, for some reason it doesn’t work properly, and Netbeans throws some exceptions into the debugger whenever I try to load or save the file.
private void openActionPerformed(java.awt.event.ActionEvent evt)
{
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
// What to do with the file, e.g. display it in a TextArea
CSVReader reader = new CSVReader(new FileReader( file.getAbsolutePath()));
List myEntries = reader.readAll();
table (myEntries.toArray());
} catch (IOException ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled by user.");
}
}
that’s my code for the specific problem.
How do I make this work properly?
only the suggestions
you can to put Vector or Object[] to the JTable directly
for
java.util.Listyou have to implements custom AbstractTableModel, becauseJTableand itsXxxTableModelis based on prematureVector or Object[]all updates to the
XxxTableModelmust be done on EventDispatchThreadfor better help sooner post an SSCCE, where contens from
CSV Fileshould be hardcoded to thejava.util.Listdirectlyall data for
JTable(view) are stored intoXxxTableModel(model)