Example usage for javax.swing JFileChooser showOpenDialog

List of usage examples for javax.swing JFileChooser showOpenDialog

Introduction

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

Prototype

public int showOpenDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up an "Open File" file chooser dialog.

Usage

From source file:com.imag.nespros.gui.plugin.GraphEditor.java

private static void initMenu() {
    JMenu menu = new JMenu("File");
    menu.add(new AbstractAction("Make Image") {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            int option = chooser.showSaveDialog(demo);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                demo.writeJPEGImage(file);
            }/*from ww  w.ja  v a2 s .  c  o m*/
        }
    });
    menu.add(new AbstractAction("Print") {
        public void actionPerformed(ActionEvent e) {
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable(demo);
            if (printJob.printDialog()) {
                try {
                    printJob.print();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    menu.add(new AbstractAction("Save topology") {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            int option = chooser.showSaveDialog(demo);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                try {
                    demo.save(file);
                    frame.setTitle(file.getName());
                } catch (IOException ex) {
                    Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    menu.add(new AbstractAction("Load topology") {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            int option = chooser.showOpenDialog(demo);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                try {
                    //EPGraph.getInstance().resetMapping();
                    simu.resetMapping();
                    demo.load(file);
                    frame.setTitle("Simulator - " + file.getName());
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    JMenu menu2 = new JMenu("View");
    menu2.add(new AbstractAction("Layout") {
        @Override
        public void actionPerformed(ActionEvent e) {
            Layout l = new CircleLayout<Device, ComLink>(Topology.getInstance().getGraph());
            l.setInitializer(vv.getGraphLayout());
            l.setSize(vv.getSize());
            LayoutTransition<Device, ComLink> lt = new LayoutTransition<>(vv, vv.getGraphLayout(), l);
            Animator animator = new Animator(lt);
            animator.start();
            vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
            vv.repaint();
        }
    });
    menu2.add(new AbstractAction("Event Composition Networks") {
        @Override
        public void actionPerformed(ActionEvent e) {
            showEPGraph(EPGraph.getInstance().getGraph());
        }
    });
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(menu);
    menuBar.add(menu2);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(demo);
    frame.pack();
    frame.setVisible(true);
    buildEPGraphs();
    showEPGraph(EPGraph.getInstance().getGraph());
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void changeBaseDir() {
    File baseDir = new File(iliasProperties.getBaseDirectory());
    JFileChooser fileChooser = new JFileChooser(baseDir);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(mainFrame)) {
        String s = fileChooser.getSelectedFile().getAbsolutePath();
        JOptionPane.showMessageDialog(mainFrame, "Der neue Speicherort ist jetzt " + s, "Neuer Speicherort",
                JOptionPane.INFORMATION_MESSAGE);
        iliasProperties.setBaseDirectory(s);
        saveProperties(iliasProperties);
    } else {//from w  ww .  j a  v  a  2 s  .c o  m
        JOptionPane.showMessageDialog(mainFrame,
                "Der alte Speicherort wird beibehalten " + baseDir.getAbsolutePath(), "Speicherort",
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void openDatastoreWithUserPrompt() {
    if (!canCloseDatastore()) {
        return;//from www  .  j ava 2  s .c  om
    }

    JFileChooser chooser = SupportedFileType.EXCEL.createFileChooser();
    File defaultDir = PreferencesManager.getSingleton().getFile(PrefKey.LAST_IO_DIR);
    if (defaultDir != null) {
        IOUtils.setFile(defaultDir, chooser);
    }

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();

        openFile(file);
    }
    updateAppearance();
}

From source file:net.pms.newgui.NavigationShareTab.java

private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);

    FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
    PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
    builderFolder.opaque(true);/*from   www  .ja va 2s  .c  o m*/

    JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    folderTableModel = new SharedFoldersTableModel();
    sharedFolders = new JTable(folderTableModel);

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
    JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));

    menuItemMarkPlayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, true);
        }
    });

    menuItemMarkUnplayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, false);
        }
    });

    popupMenu.add(menuItemMarkPlayed);
    popupMenu.add(menuItemMarkUnplayed);

    sharedFolders.setComponentPopupMenu(popupMenu);

    /* An attempt to set the correct row height adjusted for font scaling.
     * It sets all rows based on the font size of cell (0, 0). The + 4 is
     * to allow 2 pixels above and below the text. */
    DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) sharedFolders.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    sharedFolders.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    sharedFolders.setIntercellSpacing(new Dimension(8, 2));

    final JPanel tmpsharedPanel = sharedPanel;

    addButton.setToolTipText(Messages.getString("FoldTab.9"));
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog((Component) e.getSource());
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                int firstSelectedRow = sharedFolders.getSelectedRow();
                if (firstSelectedRow >= 0) {
                    ((SharedFoldersTableModel) sharedFolders.getModel()).insertRow(firstSelectedRow,
                            new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                } else {
                    ((SharedFoldersTableModel) sharedFolders.getModel())
                            .addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                }
            }
        }
    });
    builderFolder.add(addButton, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    removeButton.setToolTipText(Messages.getString("FoldTab.36"));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = sharedFolders.getSelectedRows();
            if (rows.length > 0) {
                if (rows.length > 1) {
                    if (JOptionPane.showConfirmDialog(tmpsharedPanel,
                            String.format(Messages.getString("SharedFolders.ConfirmRemove"), rows.length),
                            Messages.getString("Dialog.Confirm"), JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
                for (int i = rows.length - 1; i >= 0; i--) {
                    PMS.get().getDatabase().removeMediaEntriesInFolder(
                            (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0));
                    ((SharedFoldersTableModel) sharedFolders.getModel()).removeRow(rows[i]);
                }
            }
        }
    });
    builderFolder.add(removeButton, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));

    arrowDownButton.setToolTipText(Messages.getString("SharedFolders.ArrowDown"));
    arrowDownButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < sharedFolders.getRowCount() - 1; i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i + 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i + 1, 1);
                    sharedFolders.changeSelection(i + 1, 1, false, false);

                    break;
                }
            }
        }
    });
    builderFolder.add(arrowDownButton, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));

    arrowUpButton.setToolTipText(Messages.getString("SharedFolders.ArrowUp"));
    arrowUpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < sharedFolders.getRowCount(); i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i - 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i - 1, 1);
                    sharedFolders.changeSelection(i - 1, 1, false, false);

                    break;

                }
            }
        }
    });
    builderFolder.add(arrowUpButton, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));

    scanButton.setToolTipText(Messages.getString("FoldTab.2"));
    scanBusyIcon.start();
    scanBusyDisabledIcon.start();
    scanButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (configuration.getUseCache()) {
                DLNAMediaDatabase database = PMS.get().getDatabase();

                if (database != null) {
                    if (database.isScanLibraryRunning()) {
                        int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"),
                                Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
                        if (option == JOptionPane.YES_OPTION) {
                            database.stopScanLibrary();
                            looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
                            scanButton.setEnabled(false);
                            scanButton.setToolTipText(Messages.getString("FoldTab.41"));
                        }
                    } else {
                        database.scanLibrary();
                        scanButton.setIcon(scanBusyIcon);
                        scanButton.setRolloverIcon(scanBusyRolloverIcon);
                        scanButton.setPressedIcon(scanBusyPressedIcon);
                        scanButton.setDisabledIcon(scanBusyDisabledIcon);
                        scanButton.setToolTipText(Messages.getString("FoldTab.40"));
                    }
                }
            }
        }
    });

    /*
     * Hide the scan button in basic mode since it's better to let it be done in
     * realtime.
     */
    if (!configuration.isHideAdvancedOptions()) {
        builderFolder.add(scanButton, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
    }

    scanButton.setEnabled(configuration.getUseCache());

    isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"),
            configuration.isScanSharedFoldersOnStartup());
    isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
    isScanSharedFoldersOnStartup.setContentAreaFilled(false);
    isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));

    updateSharedFolders();

    JScrollPane pane = new JScrollPane(sharedFolders);
    Dimension d = sharedFolders.getPreferredSize();
    pane.setPreferredSize(new Dimension(d.width, sharedFolders.getRowHeight() * 2));
    builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7, CellConstraints.DEFAULT, CellConstraints.FILL),
            colSpec, orientation));

    return builderFolder;
}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

@Override
public Collection<Throwable> call() throws Exception {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    List<BamFileRef> bams = new ArrayList<BamFileRef>();

    final List<String> args = getInputFiles();
    List<File> IN = new ArrayList<File>();

    if (args.isEmpty()) {
        LOG.info("NO BAM provided; Opening dialog");
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileFilter() {
            @Override//  w  w w . j  a va  2 s.c o  m
            public String getDescription() {
                return "Indexed BAM files.";
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory())
                    return true;
                return acceptBam(f);
            };
        });
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
            return wrapException("user pressed cancel");
        }
        File fs[] = chooser.getSelectedFiles();
        if (fs != null)
            IN.addAll(Arrays.asList(chooser.getSelectedFiles()));
    } else {
        for (String arg : args) {
            File filename = new File(arg);
            if (!acceptBam(filename)) {
                return wrapException(
                        "Cannot use " + filename + " as input Bam. bad extenstion ? index missing ?");
            }
            IN.add(filename);
        }
    }

    for (File in : IN) {
        try {
            bams.add(create(in));
        } catch (Exception err) {
            return wrapException(err);
        }
    }
    if (bams.isEmpty()) {
        return wrapException("No Bam file");
    }
    LOG.info("showing BAM frame");
    final BamFrame frame = new BamFrame(bams);
    frame.igvIP = super.IGV_HOST;
    frame.igvPort = super.IGV_PORT;
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                frame.setBounds(50, 50, screen.width - 100, screen.height - 100);
                frame.setVisible(true);
            }
        });
    } catch (Exception err) {
        err.printStackTrace();
        System.exit(-1);
    }

    return RETURN_OK;
}

From source file:net.lmxm.ute.gui.MainFrame.java

/**
 * Action open file./*from   ww w  .  j  a v a2s .  c om*/
 */
private void actionOpenFile() {
    final String prefix = "actionOpenFile() :";

    final JFileChooser fcOpen = new JFileChooser(getCurrentDirectory());

    fcOpen.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fcOpen.setFileFilter(getFileFilter());

    final int returnVal = fcOpen.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fcOpen.getSelectedFile();

        LOGGER.debug("{} opening file {}", prefix, file.getName());

        try {
            configuration = new ConfigurationReader(file).read();

            loadAndValidatePreferences(file);

            userPreferences.setLastFileEditedPath(file.getAbsolutePath());

            refreshJobsTree();
            updateTitle();
            getJobDetailsEditorScrollPane().setViewportView(null);
        } catch (final Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    } else {
        LOGGER.debug("{} cancelled by user", prefix);
    }
}

From source file:cis_690_report.DynamicReporter.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    jTextField1.setText("");
    JFileChooser choose = new JFileChooser();
    choose.showOpenDialog(null);
    f = choose.getSelectedFile();//ww  w  .  j  av  a  2  s.  c  o  m
    String path = f.getAbsolutePath();
    jTextField1.setText(path);
    jPanel2.setVisible(true);

    header = new String[120];
    for (int x = 0; x < 120; x++) {
        header[x] = "";
    }
    String line = "";
    BufferedReader br2 = null;
    try {
        br2 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {

        while ((line = br2.readLine()) != null) {

            // use comma as separator

            String Bull[] = line.split(",");
            //  System.out.println(Bull.length);
            if (number_of_rows == 0) {
                for (int i = 0; i < Bull.length; i++) {
                    header[i] = Bull[i];
                }
            }

            number_of_rows++;

        }

    } catch (IOException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    Bulls = new String[number_of_rows - 1];
    for (int x = 0; x < Bulls.length; x++) {
        Bulls[x] = "";
    }

    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        int k = 0;
        while ((line = br3.readLine()) != null) {

            // use comma as separator

            String Bull[] = line.split(",");
            //  System.out.println(Bull.length);
            if (k != 0) {
                if (!Bull[2].equals("")) {
                    Bulls[k - 1] += Bull[2] + ("(Brand) ");
                }
                if (!Bull[6].equals("")) {
                    Bulls[k - 1] += Bull[6] + ("(RFID) ");
                }
                if (!Bull[7].equals("")) {
                    Bulls[k - 1] += Bull[7] + ("(Tag) ");
                }
                if (!Bull[8].equals("")) {
                    Bulls[k - 1] += Bull[8] + ("(Tattoo) ");
                }
                if (!Bull[9].equals("")) {
                    Bulls[k - 1] += Bull[9] + ("(Other) ");
                }
                Bulls[k - 1] += ":" + k;

            }
            k++;
        }

    } catch (IOException ex) {
        Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (int y = 0; y < Bulls.length; y++) {
        System.out.print(Bulls[y]);
    }

    DefaultListModel dlm = new DefaultListModel();
    for (int y = 0; y < header.length; y++) {
        dlm.addElement(header[y] + ": " + y);
    }
    jList1.setModel(dlm);
    jPanel1.setVisible(false);
}

From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java

private void importFromAtom() {
    // choose file to be transformed
    OutlineJPanel.getInstance().clear();
    MindRaider.profile.setActiveOutlineUri(null);
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fc.getSelectedFile();
        MindRaider.profile.deleteActiveModel();
        logger.debug(Messages.getString("MindRaiderJFrame.importingTWikiTopic", file.getAbsolutePath()));

        // perform it async
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame("Atom Import",
                        "Importing Outline from Atom...");
                try {
                    MindRaider.outlineCustodian.importNotebook(OutlineCustodian.FORMAT_ATOM,
                            (file != null ? file.getAbsolutePath() : null), progressDialogJFrame);
                } finally {
                    if (progressDialogJFrame != null) {
                        progressDialogJFrame.dispose();
                    }//w ww .  ja va 2 s.com
                }
                return null;
            }
        };
        worker.start();
    } else {
        logger.debug(Messages.getString("MindRaiderJFrame.openCommandCancelledByUser"));
    }
}

From source file:IHM.FenetrePrincipale.java

private void btnPhotoArticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPhotoArticleActionPerformed
    JFileChooser chooser = new JFileChooser(new File(".")); // on fait selectionner a l'utilsateur le fichier voulie

    chooser.setDialogTitle("ouvrir une image");

    int reponse = chooser.showOpenDialog(this);

    if (reponse == JFileChooser.APPROVE_OPTION) {

        InputStream input = null;

        f = chooser.getSelectedFile(); // on rcupre le fichir

        nomPhoto = f.getName(); // on rcupre le nom de fichier
        nomF = f.getAbsolutePath(); // on rcupere le chemin absolue du ficheir

        txtNomPhotoA.setText(nomPhoto);/*from   w w w . j  a  va  2s  .  c o m*/

    }
}

From source file:ctPrincipal.Principal.java

private File openImagem(String Dir, boolean lista) {
    JFileChooser fileChooser = new JFileChooser();
    BufferedImage buff = null;// w w  w  .  ja va  2  s.co m
    String caminho = null;
    try {
        caminho = new File(".").getCanonicalPath() + Dir;
    } catch (IOException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    fileChooser.setCurrentDirectory(new File(caminho));
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Images", "jpg", "png", "gif", "bmp"));
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setMultiSelectionEnabled(true);
    int result = fileChooser.showOpenDialog(getComponent(0));
    if (result == JFileChooser.APPROVE_OPTION) {
        if (lista) {
            File[] selectedFile = fileChooser.getSelectedFiles();
            arquivos = new String[selectedFile.length];
            for (int i = 0; i < selectedFile.length; i++) {
                selectedFile[i].setReadable(Boolean.TRUE);
                arquivos[i] = selectedFile[i].getAbsolutePath();
            }
            jLTotal.setText("Total de Imagens : " + arquivos.length);
        } else {
            File selectedFile = fileChooser.getSelectedFile();
            return selectedFile;
        }

    }
    return null;
}