private static int showNativeFileDialog(final JFileChooser chooser) {
    final FileDialog result = new FileDialog((Frame) chooser.getParent());

    result.setDirectory(chooser.getCurrentDirectory().getPath());

    final File selected = chooser.getSelectedFile();
    result.setFile(selected == null ? "" : selected.getPath());
    result.setFilenameFilter(
        (dir, name) ->
            chooser.getFileFilter().accept(new File(dir.getPath() + File.pathSeparator + name)));

    if (chooser.getDialogType() == SAVE_DIALOG) {
      result.setMode(FileDialog.SAVE);
    } else {
      // The native dialog only support Open and Save
      result.setMode(FileDialog.LOAD);
    }

    if (chooser.getFileSelectionMode() == DIRECTORIES_ONLY) {
      System.setProperty("apple.awt.fileDialogForDirectories", "true");
    }

    // Display dialog
    result.setVisible(true);

    System.setProperty("apple.awt.fileDialogForDirectories", "false");
    if (result.getFile() == null) {
      return CANCEL_OPTION;
    }

    final String selectedDir = result.getDirectory();
    chooser.setSelectedFile(
        new File(FileUtils.ensureTrailingSlash(selectedDir) + result.getFile()));
    return APPROVE_OPTION;
  }
Whether to ask for an existing file to be overwritten. Only makes sense in dialogs of type
<code>JFileChooser.SAVE_DIALOG</code> or <code>JFileChooser.CUSTOM_DIALOG</code>.

@see JFileChooser#setDialogType(int)
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/CFileChooser.java