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

Java examples for Swing:JFileChooser

Description

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

Demo Code


//package com.java2s;
import java.awt.Component;
import java.io.File;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;

public class Main {
    /**//from  w w w.ja v  a 2  s. co  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 Tutorials