java - how to get file names exisiting in a folder and put it in Jtable -
when run programme, first file name repeated many times files exist in chosen folder (as rows). example, if have 3 files in folder, file1, file2 , file 3, after running programme jtable return:
file1 file1 file1
here code:
file files = new file(directory); file[] listoffiles = files.listfiles(); defaulttablemodel dtm = new defaulttablemodel(); dtm.getdatavector().removeallelements(); dtm.firetabledatachanged(); vector datarows = new vector(); dtm.addcolumn("nom"); (file fichier : listoffiles) { if (fichier.isfile()) { filenames = fichier.getname(); if (filenames.endswith(".txt") || filenames.endswith(".txt")) { datarows.add(filenames); dtm.addrow(datarows); } } } tblfile.setmodel(dtm);
create new instance of vector
datarows
each file, otherwise you're adding names columns
Comments
Post a Comment