Results 1 to 2 of 2
- 07-31-2009, 11:24 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 1
- Rep Power
- 0
Populating a gui list box with the files in a directory
I need to populate a list box with the names of a directory files.
For example
I have a folder called x. In that folder there is the following files
1.csv
2.csv
3.csv
Now I need to populate the my gui list box to populate fields with
1.csv
2.csv
3.csv
Here is my code so far
Public class dir{
File folder = new File("c:/mydocument/");
File [] listofFiles=folder.listFiles();
}
Now that I have the lisofFiles
how do i pass the values to my main gui class
An example code would be greatly apreciated.
}
- 08-10-2009, 04:50 PM #2
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
You are correct in the listing of the files. The following solution assumes that a GUI list box is a JList.
If you look under the Java API for JList you will find a method called setListData... this is the method you are looking for.
The following is a quick preview of what you code should look like
Java Code:public class dir { public dir() { File folder = new File("c:/mydocument/"); File [] listofFiles=folder.listFiles(); //initialize the JList JList list = new JList(); //set the listing of the directory as the data for the JList list.setListData(listofFiles); //add the list to whatever container you need .... } }
Similar Threads
-
Populating JTree With Directory Info
By SilentCodingOne in forum AWT / SwingReplies: 0Last Post: 07-07-2009, 02:37 PM -
(Recursively?) Getting Files in a Directory
By Singing Boyo in forum New To JavaReplies: 2Last Post: 05-21-2009, 08:37 AM -
Populating a drop down list from a database
By matpj in forum New To JavaReplies: 0Last Post: 01-19-2009, 12:14 PM -
how to list certain files in a given directory in java
By corpusluteum in forum New To JavaReplies: 6Last Post: 09-24-2008, 12:19 AM -
How can I get list of files in a directory
By karma in forum New To JavaReplies: 2Last Post: 12-14-2007, 11:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks