Can't recall what the JTextField object was, but you can get a String from it by
(I have to make up an object to use for demonstration)
JTextField field = new JTextField(40);
String path = field.getText();
File dir;
try
{
dir = new File(path);
}
catch(NullPointerException npeRef)
{
// what to do if the file pathname is null
}
String[] children = dir.list();
if (children == null) {
System.out.println("does not exist or is not a directory");
} else {
for (int i = 0; i < children.length; i++) {
String filename = children[i];
System.out.println(filename);
}
}
if (children != null)
{
JList list = new JList(children);
JScrollPane jsp = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.add(jsp);
}
Also, I can't see why your main method or whatever needs to be throwing any Exceptions itself, i.e. with a throws clause like you're doing.