On Feb 20, 2007, at 1:45 PM, Joel Uckelman wrote:
>
> I checked into this, both on Linux and Windows, and it seems that this
> behavior---having the previous file selected in the dialog---isn't
> possible
> given the API that Java provides for native dialogs. (If anyone
> sees a way
> to do this that I don't, let me know.) All that setFile() seems to
> do is
> put the filename in the filename text field, without selecting
> anything---
> an aggravating state of affairs, given that all of the file
> choosers that
> Sun considers native have that capability.
Well, it's not definitive, but trying this on Mac OS X,
the awt FileDialog exhibits the following behavior, when
both the directory and the file are explicitly set using
the setDirectory and setFile methods. The answer is that
it depends on whether one is using LOAD or SAVE mode:
If mode = FileDialog.SAVE
then the file is NOT selected, but the text is set.
If mode = FileDialog.LOAD
then the file IS selected and the text is set.
// Quick test program follows:
import java.awt.*;
public class TestFileDialog2 {
static void test(Frame f, int mode, String title) {
FileDialog dialog = new FileDialog(f, title, mode);
dialog.setDirectory(System.getProperty("user.dir"));
dialog.setFile("TestFileDialog2.java");
dialog.setVisible(true);
System.out.println("Returns " + dialog.getFile());
}
public static void main (String[] args) {
Frame f = new Frame();
test(f, FileDialog.SAVE, "Test SAVE");
test(f, FileDialog.LOAD, "Test LOAD");
System.exit(0);
}
}
// End of program.