Here you can find the source of getSelectedFiles(JFileChooser chooser)
public static File[] getSelectedFiles(JFileChooser chooser)
//package com.java2s; /*/* ww w .j a v a 2s . c o m*/ * Copyright (c) 2016 Vivid Solutions. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * * http://www.eclipse.org/org/documents/edl-v10.php. */ import java.awt.Container; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JList; public class Main { /** * Workaround for Swing bug: JFileChooser does not support multi-file selection * See Sun bug database 4218431. * http://manning.spindoczine.com/sbe/files/uts2/Chapter14html/Chapter14.htm) */ public static File[] getSelectedFiles(JFileChooser chooser) { // Although JFileChooser won't give us this information, // we need it... Container c1 = (Container) chooser.getComponent(3); JList list = null; while (c1 != null) { Container c = (Container) c1.getComponent(0); if (c instanceof JList) { list = (JList) c; break; } c1 = c; } Object[] entries = list.getSelectedValues(); File[] files = new File[entries.length]; for (int k = 0; k < entries.length; k++) { if (entries[k] instanceof File) files[k] = (File) entries[k]; } return files; } }