Example usage for javax.swing JFileChooser ERROR_OPTION

List of usage examples for javax.swing JFileChooser ERROR_OPTION

Introduction

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

Prototype

int ERROR_OPTION

To view the source code for javax.swing JFileChooser ERROR_OPTION.

Click Source Link

Document

Return value if an error occurred.

Usage

From source file:org.ut.biolab.medsavant.client.view.dialog.SavantExportForm.java

private void chooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Save Savant Project");
    fc.setDialogType(JFileChooser.SAVE_DIALOG);
    fc.addChoosableFileFilter(new ExtensionsFileFilter(new String[] { "svp" }));
    fc.setMultiSelectionEnabled(false);//from   ww w  .  jav  a2  s .c  o  m

    int result = fc.showDialog(null, null);
    if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) {
        return;
    }

    outputFile = fc.getSelectedFile();
    String path = outputFile.getAbsolutePath();
    outputFileField.setText(path);
    exportButton.setEnabled(true);
}

From source file:ui.FtpDialog.java

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

    if (connected) {
        JFileChooser uploadFileChooser = new JFileChooser();
        uploadFileChooser.setPreferredSize(new Dimension(650, 450));

        File rootDirectory = new File("C:\\");

        uploadFileChooser//  w w w  .j a va  2  s  . c o m
                .setCurrentDirectory(uploadFileChooser.getFileSystemView().getParentDirectory(rootDirectory));

        uploadFileChooser.setDialogTitle("File to upload");
        int result = uploadFileChooser.showOpenDialog(this);
        switch (result) {

        case JFileChooser.APPROVE_OPTION:
            selectedFile = uploadFileChooser.getSelectedFile();

            Trace.trc("File to upload: " + selectedFile.getName() + " File size: "
                    + FileUtils.byteCountToDisplaySize(selectedFile.length()));

            if (connected) {
                if (!selectedFile.equals(null)) {
                    try {
                        input = new FileInputStream(selectedFile);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    pb = new ProgressBar();
                    pb.execute();

                    uploadFileChooser.setVisible(false);

                } else {
                    JOptionPane.showMessageDialog(rootFrame, "No file to upload has been chosen!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!",
                        "Error", JOptionPane.ERROR_MESSAGE);
            }
            break;

        case JFileChooser.CANCEL_OPTION:
            Trace.trc("Closing file chooser dialog");
            break;

        case JFileChooser.ERROR_OPTION:
            Trace.trc("An error occured");
            break;
        }

    } else {
        JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error",
                JOptionPane.ERROR_MESSAGE);
    }

}