-1
Does anyone know how to move from a csv file to a jtable? Currently but lists everything in the first column.
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
try {
File file = new File("Users.csv");
if (!file.exists()) {
file.createNewFile();
}
FileReader fr = new FileReader(file.getAbsoluteFile());
BufferedReader br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null) {
model.addRow(new String[] {line});
}
br.close();
fr.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
Add a [mcve] of your code and an example excerpt of your csv data so that it is possible to simulate the problem.
– user28595
Usually csv files come unstopped by a dot and comma (;) or other delimiting character. Break the string by the delimiter inside the while and then mount the string array with the broken values so that each one is in a cell of the table.
– Wagner Soares
can show an example @Wagnersoares ?
– Francisco Trindade