1
我想從文件選擇器中選擇多個文件並將這些值放入JTable
。我試過這樣,但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.");
}
它的工作很多感謝名單@ – user2136160
user2136160:您能接受這個答案通過單擊[空對勾(http://meta.stackexchange.com/questions/5234/how-does-accepting-an -answer-work/5235#5235)在左邊。 – trashgod