Java JFileChooser browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent)

Here you can find the source of browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent)

Description

Uses the fileChooser to browse a (not further filtered) file and put the path into the list(-model)

License

Open Source License

Parameter

Parameter Description
textField a parameter

Declaration

public static void browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;
import java.io.File;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;

public class Main {
    /**//from  w ww  .  ja  v a 2 s .  c o  m
     * Uses the fileChooser to browse a (not further filtered) file and put the
     * path into the list(-model)
     * 
     * @param textField
     */
    public static void browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent) {
        fileChooser.setMultiSelectionEnabled(true);
        int returnVal = fileChooser.showOpenDialog(parent);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            for (File file : fileChooser.getSelectedFiles()) {
                listModel.addElement(file.getAbsolutePath());
            }
        }
    }
}

Related

  1. askForFile(String title, File rootDir)
  2. askForFiles(File rootDir)
  3. askForFolder(File rootDir)
  4. askUserForFileURL(Component aParent, boolean bOpen)
  5. chooseDirectory(Component parentComponent, File directory, String title)
  6. chooseDirectory(String name, final String desc, File curdir)
  7. chooseFile()
  8. chooseFile()