2

I'm beginning to dabble with GUI frameworks and have hit a wall in the development of a data-managing GUI I'm creating for my father, using AWT.

I want to select a directory using FileDialog, in order to retrieve its PATH but for now I can only select files

There aren't concrete restrictions but for my sake:

  • It only uses AWT framework, no Swing
  • It's OS portable
  • It specifically selects directories, NOT files

I've searched for about 1.5 hours with mostly fruitless results, here's my attempt at my goal:

private static String fileDialog(Frame frame, String rootDir) {
    FileDialog filedialog = new FileDialog(frame, "Choose a File", FileDialog.LOAD);
    filedialog.setDirectory(rootDir);
    filedialog.setVisible(true);
    String dirName = filedialog.getDirectory();
    return dirName;
}

However I did discover a partial solution here, using:

System.setProperty(apple.awt.fileDialogForDirectories, “true”)

But, I want it to be OS portable, which this last line does not allow.

Community
  • 1
  • 1
  • *"It only uses AWT framework, no Swing"* Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Dec 27 '15 at 05:13

0 Answers0