tags:

views:

47

answers:

2

I face the following strange problem while using JFileChooser

package sandbox;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author yccheok
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        final JFileChooser chooser = new JFileChooser();
        chooser.setAcceptAllFileFilterUsed(false);

        // STRANGE! Using "TEST", when dialog box pop up, you see empty in file name field.
        // However, using other name like "TESTX", when dialog box pop up, you see "TESTX" in file name field.
        //chooser.setSelectedFile(new File("TESTX"));
        chooser.setSelectedFile(new File("TEST"));

        chooser.showOpenDialog(null);
    }
}

Is this my machine problem? Or you all face the same problem too? For your information, I am using Vista.

+2  A: 

Both new File("TESTX") and new File("TEST") will display TESTX and TEST respectively in the text field of the JFileChooser (as expected).

Bart Kiers
It displays for me too
Telcontar
A: 

Maybe for some reason new File("TEST") returns null for you.

Run it in debug to see.

JRL
`new File("TEST")` can't return null. It either results in a new `File` object or throws an exception. It can *never* result in null.
Joachim Sauer