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:com.mirth.connect.client.ui.MessageImportDialog.java

private void browseSelected() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    if (userPreferences != null) {
        File currentDir = new File(userPreferences.get("currentDirectory", ""));

        if (currentDir.exists()) {
            chooser.setCurrentDirectory(currentDir);
        }/*w w  w.  j a  v a  2  s.  c  o  m*/
    }

    if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) {
        if (userPreferences != null) {
            userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath());
        }

        fileTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}

From source file:cool.pandora.modeller.ui.handlers.base.AddDataHandler.java

/**
 * addData.//from w w w .  j a  v  a  2s  .com
 */
void addData() {
    final File selectFile = new File(File.separator + ".");
    final JFrame frame = new JFrame();
    final JFileChooser fc = new JFileChooser(selectFile);
    fc.setDialogType(JFileChooser.OPEN_DIALOG);
    fc.setMultiSelectionEnabled(true);
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.setDialogTitle("Add File or Directory");
    final int option = fc.showOpenDialog(frame);

    if (option == JFileChooser.APPROVE_OPTION) {
        final File[] files = fc.getSelectedFiles();
        final String message = ApplicationContextUtil.getMessage("bag.message.filesadded");
        if (files != null && files.length > 0) {
            addBagData(files);
            ApplicationContextUtil.addConsoleMessage(message + " " + getFileNames(files));
        } else {
            final File file = fc.getSelectedFile();
            addBagData(file);
            ApplicationContextUtil.addConsoleMessage(message + " " + file.getAbsolutePath());
        }
        bagView.bagPayloadTreePanel.refresh(bagView.bagPayloadTree);
        bagView.updateAddData();
    }
}

From source file:com.antelink.sourcesquare.gui.controller.SourceSquareController.java

public void bind() {

    this.view.getSelectButtonLabel().addMouseListener(new MouseListener() {

        @Override// w  w  w  . j ava 2s  .c  om
        public void mouseReleased(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseClicked(MouseEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileHidingEnabled(false);
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int showDialog = fileChooser.showDialog(SourceSquareController.this.view, "Select directory");
            if (showDialog == JFileChooser.APPROVE_OPTION) {
                SourceSquareController.this.view.getTextField()
                        .setText(fileChooser.getSelectedFile().getAbsolutePath());
            }

        }
    });

    this.view.getScanButtonLabel().addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            File toScan = new File(SourceSquareController.this.view.getTextField().getText());
            if (!toScan.exists() || toScan.list().length == 0) {
                JOptionPane.showMessageDialog(SourceSquareController.this.view,
                        "Choose a valid and not empty directory", null, JOptionPane.ERROR_MESSAGE);
                return;
            }
            SourceSquareController.this.view.setVisible(false);
            SourceSquareController.this.eventBus.fireEvent(new StartScanEvent(toScan));

        }
    });

}

From source file:filesscanner.MainWindow.java

private void saveToJSONBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveToJSONBtnActionPerformed

    JSONObject object = new JSONObject();

    for (int i = 0; i < modelFiles.getSize(); i++) {

        object.put("filename" + i, modelFiles.get(i).toString());

    }// w w w  .ja v  a  2s. c  o  m

    File file = new File("C:");
    JFileChooser chooser = ShowChooser(file);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int res = chooser.showDialog(this, "  ? ??!!!");
    if (res == JFileChooser.APPROVE_OPTION) {

        try {
            Writer writer = new FileWriter(chooser.getSelectedFile());
            object.writeJSONString(writer);
            JOptionPane.showMessageDialog(rootPane, "SAVED SUCCESFULLY!!!");
            writer.flush();
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane, "Something bad!!!");
        }

    }

}

From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java

private void promptForGradleBaseDir() {
    JFileChooser c = new JFileChooser();
    c.setDialogTitle(/*from ww  w .j  a  v  a2 s  . c  o m*/
            "Pick the top level directory to use when viewing dependencies (in case you have a multi-module project)");
    c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = c.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        gradleBaseDir = c.getSelectedFile().getPath();
    }
}

From source file:com.ejisto.event.listener.SessionRecorderManager.java

private File selectOutputDirectory(Component parent, String directoryPath, boolean saveLastSelectionPath,
        SettingsRepository settingsRepository) {
    String targetPath = null;// ww  w  .j  av a 2s  .  c  om
    Path savedPath = null;
    if (StringUtils.isNotBlank(directoryPath)) {
        savedPath = Paths.get(directoryPath);
        Path selectionPath = savedPath.getParent();
        if (selectionPath != null) {
            targetPath = selectionPath.toString();
        }
    }
    JFileChooser fileChooser = new JFileChooser(targetPath);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setSelectedFile(savedPath != null ? savedPath.toFile() : null);
    fileChooser.setDialogTitle(getMessage("session.record.save.target"));

    return GuiUtils.openFileSelectionDialog(parent, saveLastSelectionPath, fileChooser, LAST_OUTPUT_PATH,
            settingsRepository);
}

From source file:filesscanner.MainWindow.java

private JFileChooser ShowChooser(File f) {
    JFileChooser chooser = new JFileChooser(f);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    return chooser;
}

From source file:edu.clemson.lph.civet.addons.VspsCviFile.java

public void importVspsFile(Window parent) {
    String sVspsDir = CivetConfig.getVspsDirPath();
    File fDir = new File(sVspsDir);
    JFileChooser open = new JFileChooser(fDir);
    Action details = open.getActionMap().get("viewTypeDetails");
    details.actionPerformed(null);/*from   w ww.j a  v a  2  s .  c o  m*/
    open.setDialogTitle("Civet: Open PDF File");
    open.setFileSelectionMode(JFileChooser.FILES_ONLY);
    open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv"));
    open.setMultiSelectionEnabled(false);
    int resultOfFileSelect = open.showOpenDialog(parent);
    if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) {
        File fIn = open.getSelectedFile();
        saveme(parent, fIn);
        //          vsps.printme();
    }

}

From source file:TextFileHandler.java

public File openDirectory(String title) {
    File result = null;/*from w w  w. ja v a 2s .c  om*/
    JFileChooser chooser = new JFileChooser(new File("."));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (title != null)
        chooser.setDialogTitle(title);
    int retVal = chooser.showOpenDialog(null);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        result = chooser.getSelectedFile();
    }
    return result;
}

From source file:Compare.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String userDir = System.getProperty("user.home");
    JFileChooser folder = new JFileChooser(userDir + "/Desktop");
    folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folder.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files  (*.xls)", "xls");
    folder.setFileFilter(xmlfilter);/*from ww w .jav a2s.com*/
    int returnvalue = folder.showSaveDialog(this);

    File myfolder = null;
    if (returnvalue == JFileChooser.APPROVE_OPTION) {
        myfolder = folder.getSelectedFile();
        //            System.out.println(myfolder);         
    }

    if (myfolder != null) {
        JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder);
    }

    listofFiles(myfolder);
    sortByName();

    DefaultTableModel model = (DefaultTableModel) FileDetails.getModel();

    int count = 1;
    for (Files filename : filenames1) {
        String size = Long.toString(filename.Filesize) + "Bytes";
        model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation });
    }

}