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:VentanaPrincipal.java

private void descargarFichero() throws IOException {
    String directorio = lblRuta.getText();
    cliente.changeWorkingDirectory(directorio);
    JFileChooser chooser = new JFileChooser();
    cliente.enterLocalPassiveMode();/*from  w  w  w .  java2  s . c  om*/
    cliente.setFileType(FTP.BINARY_FILE_TYPE);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        BufferedOutputStream out = new BufferedOutputStream(
                new FileOutputStream(chooser.getSelectedFile().getAbsolutePath() + "/" + listFicheros
                        .getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-"))));
        if (cliente.retrieveFile(
                listFicheros.getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-")),
                out))
            lblMens.setText("Descargado correctamente ");
        else
            lblMens.setText("No se ha podido descargar");
        out.close();
    }
}

From source file:com.genericworkflownodes.knime.nodes.io.OutputFileNodeDialog.java

/**
 * New pane for configuring MimeFileExporter node dialog.
 *///  w ww .ja  va 2 s.c o  m
public OutputFileNodeDialog(final String settingsName) {
    this.settingsName = settingsName;
    dialogPanel = new JPanel();
    componentContainer = new JPanel();
    textField = new JTextField();
    textField.setPreferredSize(new Dimension(300, textField.getPreferredSize().height));
    searchButton = new JButton("Browse");
    searchButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser jfc = new JFileChooser();
            if (!"".equals(textField.getText().trim())
                    && new File(textField.getText().trim()).getParent() != null) {
                jfc.setCurrentDirectory(new File(textField.getText().trim()).getParentFile());
            }

            jfc.setAcceptAllFileFilterUsed(false);
            jfc.setFileFilter(extensionFilter);

            // int returnVal = jfc.showSaveDialog(dialogPanel);
            jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = jfc.showDialog(dialogPanel, "Select output file");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                // validate extension
                if (!extensionFilter.accept(jfc.getSelectedFile())) {
                    String message = "The selected output file has an invalid file extension.\n";
                    if (extensionFilter.getExtensions().length == 1) {
                        message += "Please choose a file with extension: " + extensionFilter.getExtensions()[0];
                    } else {
                        message += "Please choose a file with on of the following extensions: ";
                        message += StringUtils.join(extensionFilter.getExtensions(), ", ");
                    }
                    JOptionPane.showMessageDialog(getPanel(), message, "Selected Output File is invalid.",
                            JOptionPane.WARNING_MESSAGE);
                }
                textField.setText(jfc.getSelectedFile().getAbsolutePath());
            }
        }
    });
    setLayout();
    addComponents();

    addTab("Choose File", dialogPanel);
}

From source file:coreferenceresolver.gui.MainGUI.java

private void inputFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFileBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose an input file");
    inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        inputFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath());
    } else {/*from  w  w  w .  j a va 2s . co m*/
        noteTF.setText("No input file selected");
    }
}

From source file:coreferenceresolver.gui.MainGUI.java

private void markupFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markupFileBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose an markup file");
    inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        markupFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath());
    } else {/* w  ww  .ja  va  2s  . c  o  m*/
        noteTF.setText("No markup file selected");
    }
}

From source file:coreferenceresolver.gui.MainGUI.java

private void chooseTestingFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseTestingFileBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose an testing file");
    inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        testingFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath());
    } else {//from  w w w .  j  a  v a 2 s  .  co m
        noteTF.setText("No testing file selected");
    }
}

From source file:coreferenceresolver.gui.MainGUI.java

private void chooseTrainingFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseTrainingFileBtnActionPerformed
    // TODO add your handling code here:
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose a training file");
    inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        trainingFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath());
    } else {//from   w  w w  . jav  a 2  s. c  om
        noteTF.setText("No training file selected");
    }
}

From source file:coreferenceresolver.gui.MainGUI.java

private void markupBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markupBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose where your markup file saved");
    inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        String[] inputFilePath = inputFilePathTF.getText().split("\\\\");
        String inputFileName = inputFilePath[inputFilePath.length - 1];
        markupFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator
                + inputFileName + ".markup");
        noteTF.setText("Markup waiting ...");
        new Thread(new Runnable() {
            @Override/*from  w  w w  . j  av a2 s  .  co m*/
            public void run() {
                try {
                    MarkupMain.markup(inputFilePathTF.getText(), markupFilePathTF.getText());
                    noteTF.setText("Markup done!");
                    String folderPathOpen = markupFilePathTF.getText().substring(0,
                            markupFilePathTF.getText().lastIndexOf(File.separatorChar));
                    Desktop.getDesktop().open(new File(folderPathOpen));
                } catch (IOException ex) {
                    Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    } else {
        return;
    }
}

From source file:coreferenceresolver.gui.MainGUI.java

private void testBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose where your testing file saved");
    inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        testingFilePathTF/*  www . ja v a  2  s  .  c  o  m*/
                .setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "test.arff");
        noteTF.setText("Create testing file waiting ...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TrainingMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(),
                            testingFilePathTF.getText(), false);
                    noteTF.setText("Create testing file done!");
                    String folderPathOpen = testingFilePathTF.getText().substring(0,
                            testingFilePathTF.getText().lastIndexOf(File.separatorChar));
                    Desktop.getDesktop().open(new File(folderPathOpen));
                } catch (Exception ex) {
                    Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    } else {
        noteTF.setText("No testing file location selected");
    }
}

From source file:com.emental.mindraider.ui.dialogs.AttachmentJDialog.java

/**
 * Concetructor./*from  w ww  .  jav a  2s  .c o  m*/
 * 
 * @param noteResource
 *            The concept resource.
 * @param dragAndDropReference
 *            The drag'n'drop reference.
 */
public AttachmentJDialog(ConceptResource conceptResource, DragAndDropReference dragAndDropReference) {

    super(Messages.getString("AttachmentJDialog.title"));
    this.conceptResource = conceptResource;
    getContentPane().setLayout(new BorderLayout());
    JPanel p, pp;

    p = new JPanel();
    p.setLayout(new BorderLayout());
    JLabel intro = new JLabel("<html>&nbsp;&nbsp;" + Messages.getString("AttachmentJDialog.introduction")
            + "&nbsp;&nbsp;<br><br></html>");
    p.add(intro, BorderLayout.NORTH);
    p.add(new JLabel("<html>&nbsp;&nbsp;" + Messages.getString("AttachmentJDialog.description") + "</html>"),
            BorderLayout.CENTER);
    description = new JTextField(38);
    pp = new JPanel(new FlowLayout(FlowLayout.LEFT));
    pp.add(description);
    p.add(pp, BorderLayout.SOUTH);
    getContentPane().add(p, BorderLayout.NORTH);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.setBorder(new TitledBorder(Messages.getString("AttachmentJDialog.resource")));

    ButtonGroup attachType = new ButtonGroup();

    JPanel webPanel = new JPanel();
    webPanel.setLayout(new BorderLayout());
    webType = new JRadioButton(Messages.getString("AttachmentJDialog.web"));
    webType.setActionCommand(WEB);
    webType.addActionListener(this);
    webType.setSelected(true);
    attachType.add(webType);
    webPanel.add(webType, BorderLayout.NORTH);
    urlTextField = new JTextField("http://", 35);
    urlTextField.selectAll();
    urlTextField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                attach();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.LEFT));
    p.add(new JLabel("   "));
    p.add(urlTextField);
    webPanel.add(p, BorderLayout.SOUTH);
    mainPanel.add(webPanel, BorderLayout.NORTH);

    JPanel localPanel = new JPanel();
    localPanel.setLayout(new BorderLayout());
    JRadioButton localType = new JRadioButton(Messages.getString("AttachmentJDialog.local"));
    localType.setActionCommand(LOCAL);
    localType.addActionListener(this);
    localPanel.add(localType, BorderLayout.NORTH);
    pathTextField = new JTextField(35);
    pathTextField.setEnabled(false);
    browseButton = new JButton(Messages.getString("AttachmentJDialog.browse"));
    browseButton.setToolTipText(Messages.getString("AttachmentJDialog.browseTip"));
    browseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("AttachmentJDialog.attach"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("AttachmentJDialog.chooseAttachment"));
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int returnVal = fc.showOpenDialog(AttachmentJDialog.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                pathTextField.setText(file.toString());
            }
        }
    });
    browseButton.setEnabled(false);
    pp = new JPanel();
    pp.setLayout(new BorderLayout());
    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.LEFT));
    p.add(new JLabel("   "));
    pp.add(p, BorderLayout.NORTH);
    p.add(pathTextField);
    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(browseButton);
    pp.add(p, BorderLayout.SOUTH);
    localPanel.add(pp, BorderLayout.SOUTH);
    attachType.add(localType);
    mainPanel.add(localPanel, BorderLayout.SOUTH);

    getContentPane().add(mainPanel, BorderLayout.CENTER);

    // buttons
    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton(Messages.getString("AttachmentJDialog.attach"));

    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            attach();
        }
    });
    JButton cancelButton = new JButton(Messages.getString("AttachmentJDialog.cancel"));
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            AttachmentJDialog.this.dispose();
        }
    });
    getContentPane().add(p, BorderLayout.SOUTH);

    /*
     * drag and drop initialization
     */
    if (dragAndDropReference != null) {
        if (dragAndDropReference.getType() == DragAndDropReference.BROWSER_LINK) {
            urlTextField.setText(dragAndDropReference.getReference());
            localType.setSelected(false);
            webType.setSelected(true);
            enableWebTypeButtons();
        } else {
            pathTextField.setText(dragAndDropReference.getReference());
            localType.setSelected(true);
            webType.setSelected(false);
            enableLocalTypeButtons();
        }
        description.setText(dragAndDropReference.getTitle());
    }

    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:coreferenceresolver.gui.MainGUI.java

private void trainingBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trainingBtnActionPerformed
    // TODO add your handling code here:
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose where your training file saved");
    inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        trainingFilePathTF//from   w w w  . j ava  2  s . com
                .setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "train.arff");
        noteTF.setText("Create training file waiting ...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TrainingMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(),
                            trainingFilePathTF.getText(), true);
                    noteTF.setText("Create training file done!");
                    String folderPathOpen = trainingFilePathTF.getText().substring(0,
                            trainingFilePathTF.getText().lastIndexOf(File.separatorChar));
                    Desktop.getDesktop().open(new File(folderPathOpen));
                } catch (Exception ex) {
                    Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    } else {
        noteTF.setText("No training file location selected");
    }
}