Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2005

Tip: Looking for answers? Try searching our database.

Load the files from a directory

Thread view: 
Pep - 24 Jul 2005 22:01 GMT
Hi.
Anybody can tell me the way to load all the files from a directory and show
them into a JTable. Which is the technique to do this?.
Thanks
Andrew Thompson - 24 Jul 2005 22:17 GMT
> Anybody can tell me the way to load all the files from a directory

<http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#listFiles()>

>..and show them into a JTable.

<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTable.html>
Follow the trail to the TableModel

BTW - beginner questions are best asked in c.l.j.help.
<http://www.physci.org/codes/javafaq.jsp#cljh>

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Known To Cause Insanity In Laboratory Mice

Davisote - 25 Jul 2005 11:23 GMT
Andrew Thompson escribió:

>>Anybody can tell me the way to load all the files from a directory
>
[quoted text clipped - 7 lines]
> BTW - beginner questions are best asked in c.l.j.help.
> <http://www.physci.org/codes/javafaq.jsp#cljh>

Perfect,
Thanks
Liz - 25 Jul 2005 20:37 GMT
You can use QuickTable to implement the same feature in just three
statements

DBTable myFileTable = new DBTable();
File f = new File("C:\\temp\\");
myFileTable.refreshDataObjects(f.listFiles(), null);

You don't need to write any model.

QuickTable is a free java component (http://quicktable.org) which is an
implementation on top of JTable , but hides all the complexities and
allows to use the JTable methods. So you can just replace Jtable with
QuickTable.
Daviso - 01 Aug 2005 09:29 GMT
Yes, but the problem is the same because "C:\\temp\\" must be variable, is
not constant, so when I select the directory from the JFileChooser it give
in this way "C:\temp\", at least using my code.

Thanks

> You can use QuickTable to implement the same feature in just three
> statements
[quoted text clipped - 9 lines]
> allows to use the JTable methods. So you can just replace Jtable with
> QuickTable.
Andrew Thompson - 01 Aug 2005 09:57 GMT
Please refrain from top-posting, I find it most confusing
<http://www.physci.org/codes/javafaq.jsp#netiquette>
See further comments below.

> "Liz" <hilizbabe@yahoo.com> escribió en el mensaje

>> You can use QuickTable to implement the same feature in just three
>> statements
>>
>> DBTable myFileTable = new DBTable();
>> File f = new File("C:\\temp\\");
>> myFileTable.refreshDataObjects(f.listFiles(), null);

> Yes, but the problem is the same because "C:\\temp\\" must be variable, is
> not constant,

Well ..duhh. (We are all programmers here!)

>..so when I select the directory from the JFileChooser it give
> in this way "C:\temp\", at least using my code.

Try this..

 String s = "c:\temp";
 System.out.println(s);
 s = "c:\\temp";
 System.out.println(s);

BTW - beginner questions are best asked on
<http://www.physci.org/codes/javafaq.jsp#cljh>

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Mr Bender's Wardrobe By ROBOTANY 500

Davisote - 01 Aug 2005 12:41 GMT
> Please refrain from top-posting, I find it most confusing
> <http://www.physci.org/codes/javafaq.jsp#netiquette>
[quoted text clipped - 26 lines]
> BTW - beginner questions are best asked on
> <http://www.physci.org/codes/javafaq.jsp#cljh>

oK, RIGHT
THEN, why this doesn't work??

(dirLocal is a JLabel)
void btnSeleccionaDirectorio_actionPerformed(ActionEvent e) {
    int retval;
    JFileChooser chooser = new JFileChooser();
    //chooser.DIRECTORIES_ONLY;
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle("Select directory??");
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showDialog(this, "Select") !=
JFileChooser.APPROVE_OPTION) {
       System.exit(1);
    }
    dirLocal.setText("Local Directory: " +
chooser.getSelectedFile().getAbsolutePath());

    model.setColumnCount(0);
    model.setRowCount(0);

    int columns = 2;
    model.addColumn("Fichero");
    model.addColumn("Estado");

    loadTable(dirLocal.getText());

  }
  void loadTable(String dirLocal) {
    File myFile = new File(dirLocal);
    File[] allFiles = myFile.listFiles();
    int i, j, k;
    System.out.println("Directory: " + dirLocal);
    k = 0;
    for (i = 0; i < allFiles.length; i++) {
      if (allFiles[i].isFile()) {
        j = (new Long(allFiles[i].length())).intValue();
        if (j <=  MAX_TAM) {
          Vector row = new Vector(2);
          row.addElement(allFiles[i]);
          row.addElement(new Integer(3));
          model.insertRow(k++, row);
        }
      }
    }

Greetings
Andrew Thompson - 01 Aug 2005 15:08 GMT
> THEN, why this doesn't work??

(shrugs) Maybe it is just lazy.

It does not compile for me.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
LOADING....

Davisote - 02 Aug 2005 10:11 GMT
>>THEN, why this doesn't work??
>
> (shrugs) Maybe it is just lazy.
>
> It does not compile for me.

thanks for nothing
Aki Laukkanen - 02 Aug 2005 10:23 GMT
>>> THEN, why this doesn't work??
>>
[quoted text clipped - 3 lines]
>>
> thanks for nothing

What Andrew was trying to tell you is:
"Look at some of the error messages given by your compiler and figure it
out from there."
The compiler is even kind enough to tell you what type of error[s] you
made and approximately where on which line they are.
HTH.

Signature

-Aki "Sus" Laukkanen

Davisote - 02 Aug 2005 12:14 GMT
>>>> THEN, why this doesn't work??
>>>
[quoted text clipped - 10 lines]
> made and approximately where on which line they are.
> HTH.

Hi.
There is only one error because my var is "c:\temp" and the vector
created is null son allFiles.length give me an exception, BUT if I put
"C:\\temp" it create the vector with the files correctly.

So. Only I want the way to obtain an absolute path in the form "C:\\temp".

anyway, thanks for your reply


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.