Example usage for java.awt FileDialog setModal

List of usage examples for java.awt FileDialog setModal

Introduction

In this page you can find the example usage for java.awt FileDialog setModal.

Prototype

public void setModal(boolean modal) 

Source Link

Document

Specifies whether this dialog should be modal.

Usage

From source file:Main.java

/**
 * @param jFrame//w  w  w. ja  va 2 s  .  co m
 * @param currentDirectory
 * @return You can get the filename with fileDialog.getFile(),
 * and you can get the directory with fileDialog.getDirectory().
 * String filename = fileDialog.getDirectory() + System.getProperty("file.separator") + fileDialog.getFile();
 * 
 */
public static FileDialog letUserChooseFile(JFrame jFrame, String currentDirectory) {
    FileDialog fileDialog = new FileDialog(jFrame);
    fileDialog.setModal(true);
    fileDialog.setMode(FileDialog.LOAD);
    fileDialog.setTitle("Open a File");
    if (currentDirectory != null && !currentDirectory.trim().equals("")) {
        fileDialog.setDirectory(currentDirectory);
    }
    fileDialog.setVisible(true);
    return fileDialog;
}

From source file:com.moneydance.modules.features.importlist.io.MacOSDirectoryChooser.java

@Override
void chooseBaseDirectory() {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
    final FileDialog fileDialog = new FileDialog((Frame) null, this.getLocalizable().getDirectoryChooserTitle(),
            FileDialog.LOAD);//  ww w  .  java 2s . co  m
    fileDialog.setModal(true);
    fileDialog.setFilenameFilter(DirectoryValidator.INSTANCE);

    try {
        fileDialog.setDirectory(FileUtils.getUserDirectory().getAbsolutePath());
    } catch (SecurityException e) {
        LOG.log(Level.WARNING, e.getMessage(), e);
    }

    if (this.getBaseDirectory() != null) {
        final File parentDirectory = this.getBaseDirectory().getParentFile();
        if (parentDirectory != null) {
            fileDialog.setDirectory(parentDirectory.getAbsolutePath());
        }
    }
    fileDialog.setVisible(true);
    System.setProperty("apple.awt.fileDialogForDirectories", "false");

    if (fileDialog.getFile() == null) {
        return;
    }

    this.getPrefs()
            .setBaseDirectory(new File(fileDialog.getDirectory(), fileDialog.getFile()).getAbsolutePath());

    LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory()));
}