JFileChooser, or the JFileSelector, each of the files can be selected in its specific directory.
JMultipleFileSelector uses JFileSelectors internally so the JMultipleFileSelector is also protected against long delays when initializing the shared JFileChooser instance for the first time.
JFrame f = new JFrame("test"); JMultipleFileSelector fs = new JMultipleFileSelector(); fs.setCurrentDirectory(new File(System.getProperty("user.dir"))); fs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Action : "); JMultipleFileSelector selector = (JMultipleFileSelector)e.getSource(); File[] files = selector.getSelectedFiles(); } }); f.getContentPane().add(fs); f.pack(); f.setVisible(true);You will obtain the following result:
JMultipleFileSelector to add an option to unset the file list:true, then if will present an additional button in the interface to allow to unset the file list. In that case, the result will be an empty array of filesJFrame f = new JFrame("test"); JMultipleFileSelector fs = new JMultipleFileSelector(); fs.setHasOptionalFiles(true); fs.setCurrentDirectory(new File(System.getProperty("user.dir"))); fs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Action : "); JMultipleFileSelector selector = (JMultipleFileSelector)e.getSource(); File[] files = selector.getSelectedFiles(); } }); f.getContentPane().add(fs); f.pack(); f.setVisible(true);In that case you will have the following GUI in the Popup:
JMultipleFileSelector GUI will use the default Locale language of the platform.enfritspptdenojazhJMultipleFileSelector component. By default this is the default platform Locale, but it is possible to force the Locale by using the Component.setLocale(Locale) method on the JMultipleFileSelector component.JFrame f = new JFrame("test"); JMultipleFileSelector fs = new JMultipleFileSelector(); fs.setHasOptionalFiles(true); fs.setUnselectedFileText("No File"); fs.setCurrentDirectory(new File(System.getProperty("user.dir"))); fs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Action : "); JMultipleFileSelector selector = (JMultipleFileSelector)e.getSource(); File[] files = selector.getSelectedFiles(); } }); f.getContentPane().add(fs); f.pack(); f.setVisible(true);You will have the following GUI in the Popup:
JMultipleFileSelector can be customized by providing a FileSelectorRenderer to the file selector. By default the selector uses a DefaultFileSelectorRenderer which will show the absolute paths of the selected files.FileSelectorRenderer which will shows paths relative to a parent directory rather than absolute.Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences