local FileTableModel

Hey i have a "problem" with mine FileTableModel. I get al the values in my JTable but there isn't a ".." directory in the JTable. So i want to create a row with the option to go 1 directory up. How do i do that?

dir =new File("C:\\java");

FileTableModel model =new FileTableModel(dir);

TableSorter sorter1 =new TableSorter(model);

table =new JTable(sorter1);

sorter1.setTableHeader(table.getTableHeader());

sorter1.setSortingStatus(0, -1);

TableColumn column =null;

for (int i = 0; i < 3; i++){

column = table.getColumnModel().getColumn(i);

if (i == 0){

column.setPreferredWidth(20);

}else{

if (i == 1){

column.setPreferredWidth(160);

}

else

{

column.setPreferredWidth(80);

}

}

}

ListSelectionModel listMod1 = table.getSelectionModel();

listMod1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

listMod1.addListSelectionListener(this);

table.addMouseListener(this);

tLocal.setText(dir.getPath());

table.getTableHeader().setReorderingAllowed(false);

table.setRowHeight(20);

scrClient =new JScrollPane(table);

The filetable is created with this code:

class FileTableModelextends AbstractTableModel{

protected File dir;

protected String[] filenames;

protected String[] columnNames =new String[]{

"","name","size","last modified","directory?","readable?","writable?"

};

protected Class[] columnClasses =new Class[]{

Icon.class,String.class, Long.class, Date.class,

Boolean.class, Boolean.class, Boolean.class

};

// This table model works for any one given directory

public FileTableModel(File dir){

this.dir = dir;

this.filenames = dir.list();// Store a list of files in the directory

}

// These are easy methods

publicint getColumnCount(){return 3;}// A constant for this model

publicint getRowCount(){return filenames.length;}// # of files in dir

// Information about each column

public String getColumnName(int col){return columnNames[col];}

public Class getColumnClass(int col){return columnClasses[col];}

// The method that must actually return the value of each cell

public Object getValueAt(int row,int col){

File f =new File(dir, filenames[row]);

switch(col){

case 0:return f.isDirectory() ? folder : files;

case 1:return filenames[row];

case 2:if (f.isDirectory()==true){

returnnull;

}else{

returnnew Long(f.length());

}

case 3:return f.isDirectory() ? Boolean.TRUE : Boolean.FALSE;

case 4:return f.canRead() ? Boolean.TRUE : Boolean.FALSE;

case 5:return f.canWrite() ? Boolean.TRUE : Boolean.FALSE;

default:returnnull;

}

}

}

[6296 byte] By [Satanduvela] at [2007-11-27 1:34:19]
# 1
Pls can somebody help me, you get all the starsThx
Satanduvela at 2007-7-12 0:41:35 > top of Java-index,Java Essentials,Java Programming...
# 2
Make getRowCount return filenames.length + 1 and modify the getValueAt method to return ".." when row is 0. You still need to handle the user clicking that row.
-Kayaman-a at 2007-7-12 0:41:35 > top of Java-index,Java Essentials,Java Programming...
# 3
the answer was already given http://forum.java.sun.com/thread.jspa?threadID=5162502
Satanduvela at 2007-7-12 0:41:35 > top of Java-index,Java Essentials,Java Programming...