2

I have a Java application which uses JTables to add files for browsing. It contains only 1 column:

DefaultTableModel model = new DefaultTableModel(new String[] {"Name"}, 0);

    JTable tracks = new JTable(model){
        public boolean isCellEditable(int rowIndex, int collIndex){
            return false;
        }
    };

tracks.addMouseListener(new PopupListener());

tracks.setShowGrid(false);

Adding files to the table is done like this:

for (File file : results){
    model.addRow(new Object[] {file});
}

I need to add the actual file, not just its name because I will use it later. However, is it possible that the table shows only the file name (file.getName();) instead of the entire path?

tihomirbz
  • 95
  • 6

1 Answers1

5

..is it possible that the table shows only the file name (file.getName();) instead of the entire path?

It sure is. Use a TableCellRenderer to show just the name. See How to Use Tables - Concepts: Editors and Renderers for details.

See also the File Browser GUI for general tips (like using the icon for the file).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433