Ho una cartella, da questa estrapolo i file contenuti in essa, devo stampare a video alcuni loro attributi in formato tabellare.
Il problema sta in questo ciclocodice:class Mostra_Diff extends JPanel{ File dir1, dir2; File[] files; String col [] = {"File","Cartella","Dimensione","Data","Ora"}; String data[][]; JTableHeader head; JScrollPane scroll; JTable table; DefaultTableModel modeltable; Mostra_Diff(){ dir1= Confronta_Panel.dir; dir2= Confronta_Panel_2.dir; files = dir1.listFiles(); modeltable = new DefaultTableModel(data,col); if (files == null) { // Either dir does not exist or is not a directory } else{ for (int i=0; i<files.length; i++) { // Get filename of file or directory String filename[] = {files[i].getName(),files[i].getParent(), ""+files[i].getTotalSpace()}; modeltable.addRow(filename); } } table = new JTable(modeltable); table.setIntercellSpacing(new Dimension(20,1)); scroll = new JScrollPane(table); SetRowHight(table); table.setColumnSelectionAllowed(true); table.setAutoCreateRowSorter(true); head = table.getTableHeader(); //head.setBackground(Color.YELLOW); add(scroll); Utilities.settingPanel(this); setLayout(new FlowLayout()); } public void SetRowHight(JTable table){ int height = table.getRowHeight(); table.setRowHeight(height+10); } }
perchè se ci metto uncodice:for (int i=0; i<files.length; i++) { // Get filename of file or directory String filename[] = {files[i].getName(),files[i].getParent(), ""+files[i].getTotalSpace()}; modeltable.addRow(filename);
funzionacodice:String[] filename = { "Hannah", "Arendt", "1906-1975", " ", " " }; model.addRow(filename);

Rispondi quotando