我想从文件选择器中选择多个文件并将这些值放入JTable
. 我像这样尝试过,但相同的值在JTable
. 在打印行中,它正确打印值。
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
int returnVal = fileChooser.showOpenDialog(fileChooser);
if (returnVal==JFileChooser.APPROVE_OPTION) {
File file[] = fileChooser.getSelectedFiles();
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
Vector v = new Vector();
for (int i = 0; i < file.length; i++) {
String name;
String path;
long size;
name = file[i].getName();
path = file[i].getPath();
System.out.println("name = "+name+" path = "+path);
v.add(name);
v.add(path);
dtm.addRow(v);;
}
try {
} catch (Exception ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled by user.");
}