Example usage for javax.swing JFileChooser setFileSelectionMode

List of usage examples for javax.swing JFileChooser setFileSelectionMode

Introduction

In this page you can find the example usage for javax.swing JFileChooser setFileSelectionMode.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY",
        "JFileChooser.DIRECTORIES_ONLY",
        "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.")
public void setFileSelectionMode(int mode) 

Source Link

Document

Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories.

Usage

From source file:xtrememp.PlaylistManager.java

public void addFilesDialog(boolean playFirst) {
    JFileChooser fileChooser = new JFileChooser(Settings.getLastDir());
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(audioFileFilter);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(true);
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = fileChooser.getSelectedFiles();
        Settings.setLastDir(selectedFiles[0].getParent());
        addFiles(Arrays.asList(selectedFiles), playFirst);
    }//from   w  w w .  jav  a  2s .c o  m
}

From source file:zsk.JFCMainClient.java

/**
 * process events of ActionListener/*from ww w .ja v  a  2 s.c om*/
 * 
 */
public void actionPerformed(final ActionEvent e) {
    if (e.getSource().equals(frame.textinputfield)) {
        if (!e.getActionCommand().equals("")) {
            if (e.getActionCommand().matches(szYTREGEX))
                addYTURLToList(e.getActionCommand());
            else {
                addTextToConsole(e.getActionCommand());
                cli(e.getActionCommand().toLowerCase());
            }
        }
        synchronized (frame.textinputfield) {
            frame.textinputfield.setText("");
        }
        return;
    }

    // let the user choose another dir
    if (e.getSource().equals(frame.directorybutton)) {
        debugoutput("frame.directorybutton");
        JFileChooser fc = new JFileChooser();
        fc.setMultiSelectionEnabled(false);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        synchronized (frame.directorytextfield) {
            // we have to set current directory here because it gets lost when fc is lost
            fc.setCurrentDirectory(new File(frame.directorytextfield.getText()));
        }
        debugoutput("current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath()));
        if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        String snewdirectory = fc.getSelectedFile().getAbsolutePath();
        // append file.seperator if last character is not file.seperator (the user choosed a directory other than root)
        snewdirectory.concat(snewdirectory.endsWith(System.getProperty("file.separator")) ? ""
                : System.getProperty("file.separator"));
        File ftest = new File(snewdirectory);
        if (ftest.exists()) {
            if (ftest.isDirectory()) {
                synchronized (frame.directorytextfield) {
                    frame.directorytextfield.setText(snewdirectory);
                }
                config.setProperty("savefolder", snewdirectory);
                debugoutput("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath()));
                output("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath()));
            } else {
                output("not a directory: ".concat(snewdirectory));
            }
        } else {
            output("directory does not exist: ".concat(snewdirectory));
        }
        return;
    }

    // let the user choose another download resolution
    if (e.getActionCommand().equals(JFCMainClient.frame.hdbutton.getActionCommand())
            || e.getActionCommand().equals(JFCMainClient.frame.stdbutton.getActionCommand())
            || e.getActionCommand().equals(JFCMainClient.frame.ldbutton.getActionCommand())) {
        debugoutput("trying: ".concat(e.getActionCommand()));
        output("trying: ".concat(e.getActionCommand().toUpperCase()));

        return;
    }

    // let the user choose another video format
    if (e.getActionCommand().equals(JFCMainClient.frame.mpgbutton.getActionCommand())
            || e.getActionCommand().equals(JFCMainClient.frame.flvbutton.getActionCommand())
            || e.getActionCommand().equals(JFCMainClient.frame.webmbutton.getActionCommand())) {
        debugoutput("trying: ".concat(e.getActionCommand()));
        output("trying: ".concat(e.getActionCommand().toUpperCase()
                .concat("  ".concat(isgerman() ? "(Dateien werden immer nach MIME-Typ benannt!)"
                        : "(files will always be named according to MIME type!)"))));
        return;
    }

    if (e.getActionCommand().equals("quit")) {
        addTextToConsole(isgerman()
                ? "Programmende ausgewhlt - beende DownloadThreads, Vorgang kann eine Weile dauern!"
                : "quit requested - signaling donwload threads to terminate, this may take a while!");
        // seems to have to effect:
        //JFCMainClient.frame.repaint();
        JFCMainClient.shutdownAppl();
        return;
    }
    debugoutput("unknown action. ".concat(e.getSource().toString()));
    output("unbekannte Aktion");

}