List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
From source file:Main.java
public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(null);// w w w . j av a 2 s . co m File[] files = chooser.getSelectedFiles(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(new File("C:\\tmp")); JButton btn1 = new JButton("Show Dialog"); btn1.addActionListener(e -> fc.showDialog(frame, "Choose")); JButton btn2 = new JButton("Show Open Dialog"); btn2.addActionListener(e -> {/*from w ww . j av a 2s . com*/ int retVal = fc.showOpenDialog(frame); if (retVal == JFileChooser.APPROVE_OPTION) { File[] selectedfiles = fc.getSelectedFiles(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < selectedfiles.length; i++) { sb.append(selectedfiles[i].getName()); sb.append("\n"); } JOptionPane.showMessageDialog(frame, sb.toString()); } }); JButton btn3 = new JButton("Show Save Dialog"); btn3.addActionListener(e -> fc.showSaveDialog(frame)); Container pane = frame.getContentPane(); pane.setLayout(new GridLayout(3, 1, 10, 10)); pane.add(btn1); pane.add(btn2); pane.add(btn3); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static void main(String[] args) { try {//from w w w .j av a 2 s . com DIR.mkdirs(); if (!new File(DIR, "convert.exe").exists()) Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"), new FileOutputStream(new File(DIR, "convert.exe"))); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser jfc = new JFileChooser( new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI())); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin")); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { p("Collecting GUIDs, Converting Resources"); HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory()); p("Parsing Guiskin file"); String s = Helper.getFileContent(jfc.getSelectedFile()); String[] lines = s.split("\n"); ArrayList<String> l = new ArrayList<>(Arrays.asList(lines)); String string = ""; for (int i = 0; i < l.size(); i++) if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---")) string += l.get(i) + "\n"; Yaml yaml = new Yaml(); for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) { JSONObject o = new JSONObject((Map<?, ?>) iter.next()); p("Cconverting Guiskin"); replaceGuidDeep(o, guids, jfc.getSelectedFile()); p("Writing converted file"); Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(), jfc.getSelectedFile().getName() + ".json"), o.toString(4)); p("DONE"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:kindleclippings.word.QuizletSync.java
public static void main(String[] args) throws IOException, JSONException, URISyntaxException, InterruptedException, BackingStoreException, BadLocationException { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileNameExtensionFilter("Word documents", "doc", "rtf", "txt")); fc.setMultiSelectionEnabled(true); int result = fc.showOpenDialog(null); if (result != JFileChooser.APPROVE_OPTION) { return;/*from w w w . ja v a2 s .com*/ } File[] clf = fc.getSelectedFiles(); if (clf == null || clf.length == 0) return; ProgressMonitor progress = new ProgressMonitor(null, "QuizletSync", "loading notes files", 0, 100); progress.setMillisToPopup(0); progress.setMillisToDecideToPopup(0); progress.setProgress(0); try { progress.setNote("checking Quizlet account"); progress.setProgress(5); Preferences prefs = kindleclippings.quizlet.QuizletSync.getPrefs(); QuizletAPI api = new QuizletAPI(prefs.get("access_token", null)); Collection<TermSet> sets = null; try { progress.setNote("checking Quizlet library"); progress.setProgress(10); sets = api.getSets(prefs.get("user_id", null)); } catch (IOException e) { if (e.toString().contains("401")) { // Not Authorized => Token has been revoked kindleclippings.quizlet.QuizletSync.clearPrefs(); prefs = kindleclippings.quizlet.QuizletSync.getPrefs(); api = new QuizletAPI(prefs.get("access_token", null)); sets = api.getSets(prefs.get("user_id", null)); } else { throw e; } } progress.setProgress(15); progress.setMaximum(15 + clf.length * 10); progress.setNote("uploading new notes"); int pro = 15; int addedSets = 0; int updatedTerms = 0; int updatedSets = 0; for (File f : clf) { progress.setProgress(pro); List<Clipping> clippings = readClippingsFile(f); if (clippings == null) { pro += 10; continue; } if (clippings.isEmpty()) { pro += 10; continue; } if (clippings.size() < 2) { pro += 10; continue; } String book = clippings.get(0).getBook(); progress.setNote(book); TermSet termSet = null; String x = book.toLowerCase().replaceAll("\\W", ""); for (TermSet t : sets) { if (t.getTitle().toLowerCase().replaceAll("\\W", "").equals(x)) { termSet = t; break; } } if (termSet == null) { addSet(api, book, clippings); addedSets++; pro += 10; continue; } // compare against existing terms boolean hasUpdated = false; for (Clipping cl : clippings) { if (!kindleclippings.quizlet.QuizletSync.checkExistingTerm(cl, termSet)) { kindleclippings.quizlet.QuizletSync.addTerm(api, termSet, cl); updatedTerms++; hasUpdated = true; } } pro += 10; if (hasUpdated) updatedSets++; } if (updatedTerms == 0 && addedSets == 0) { JOptionPane.showMessageDialog(null, "Done.\nNo new data was uploaded", "QuizletSync", JOptionPane.OK_OPTION); } else { if (addedSets > 0) { JOptionPane.showMessageDialog(null, String.format("Done.\nCreated %d new sets and added %d cards to %d existing sets", addedSets, updatedSets, updatedTerms), "QuizletSync", JOptionPane.OK_OPTION); } else { JOptionPane.showMessageDialog(null, String.format("Done.\nAdded %d cards to %d existing sets", updatedTerms, updatedSets), "QuizletSync", JOptionPane.OK_OPTION); } } } finally { progress.close(); } System.exit(0); }
From source file:net.sf.vntconverter.VntConverter.java
/** * Fhrt den VntConverter mit den angegebnen Optionen aus. *//*from ww w. j a v a 2s .c o m*/ public static void main(String[] args) { try { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { // Wenn nicht, dann nicht ... } JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files (txt) and memo files (vnt)", "txt", "vnt"); fileChooser.setCurrentDirectory(new java.io.File(".")); fileChooser.setDialogTitle("Choose files to convert ..."); fileChooser.setFileFilter(filter); fileChooser.setMultiSelectionEnabled(true); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { JFileChooser directoryChooser = new JFileChooser(); directoryChooser.setCurrentDirectory(new java.io.File(".")); directoryChooser.setDialogTitle("Choose target directory ..."); directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); directoryChooser.setAcceptAllFileFilterUsed(false); if (directoryChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { VntConverter converter = new VntConverter(); String targetDirectoy = directoryChooser.getSelectedFile().getAbsolutePath(); System.out.println(targetDirectoy); for (File file : fileChooser.getSelectedFiles()) { if (file.getName().endsWith(".txt")) { converter.encode(file, new File(targetDirectoy + "\\" + file.getName().replace(".txt", ".vnt"))); } else if (file.getName().endsWith(".vnt")) { converter.decode(file, new File(targetDirectoy + "\\" + file.getName().replace(".vnt", ".txt"))); } } } } } catch (Exception e) { throw new RuntimeException("Exception caught", e); } }
From source file:Main.java
private static JFileChooser getXMLfileChooser() { JFileChooser fc = new JFileChooser(new File("../comportamientos")); // set ExtensionFile... fc.setMultiSelectionEnabled(false); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML", "xml"); fc.setFileFilter(filter);//from ww w.j a v a 2 s. c o m return fc; }
From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java
public static JFileChooser createFileChooser(final File dir, final String description, final String extension) { JFileChooser fc = new JFileChooser(dir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new FileFilter() { @Override/*from w w w . j a va 2 s .co m*/ public String getDescription() { return description; } @Override public boolean accept(final File f) { return f.isDirectory() || FilenameUtils.isExtension(f.getName(), extension); } }); return fc; }
From source file:Main.java
/** * Consistent way to chosing multiple files to open with JFileChooser. * <p>/*from w w w . j a v a 2s . c o m*/ * * @see JFileChooser#setFileSelectionMode(int) * @see #getSystemFiles(Component, int) * @param owner to show the component relative to. * @param mode selection mode for the JFileChooser. * @return File[] based on the user selection can be null. */ public static File[] getSystemFiles(Component owner, int mode, FileFilter[] filters) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(mode); jfc.setFileHidingEnabled(true); jfc.setMultiSelectionEnabled(true); jfc.setAcceptAllFileFilterUsed(true); if (filters != null) { for (int i = 0; i < filters.length; i++) { jfc.addChoosableFileFilter(filters[i]); } if (filters.length >= 1) { jfc.setFileFilter(filters[0]); } } int result = jfc.showOpenDialog(owner); if (result == JFileChooser.APPROVE_OPTION) { return jfc.getSelectedFiles(); } return new File[0]; }
From source file:net.rptools.maptool.util.AssetExtractor.java
public static void extract() throws Exception { new Thread() { @Override//from ww w .j av a2 s. c o m public void run() { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } File file = chooser.getSelectedFile(); File newDir = new File(file.getParentFile(), file.getName().substring(0, file.getName().lastIndexOf('.')) + "_images"); JLabel label = new JLabel("", JLabel.CENTER); JFrame frame = new JFrame(); frame.setTitle("Campaign Image Extractor"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(400, 75); frame.add(label); SwingUtil.centerOnScreen(frame); frame.setVisible(true); Reader r = null; OutputStream out = null; PackedFile pakfile = null; try { newDir.mkdirs(); label.setText("Loading campaign ..."); pakfile = new PackedFile(file); Set<String> files = pakfile.getPaths(); XStream xstream = new XStream(); int count = 0; for (String filename : files) { count++; if (filename.indexOf("assets") < 0) { continue; } r = pakfile.getFileAsReader(filename); Asset asset = (Asset) xstream.fromXML(r); IOUtils.closeQuietly(r); File newFile = new File(newDir, asset.getName() + ".jpg"); label.setText("Extracting image " + count + " of " + files.size() + ": " + newFile); if (newFile.exists()) { newFile.delete(); } newFile.createNewFile(); out = new FileOutputStream(newFile); FileUtil.copyWithClose(new ByteArrayInputStream(asset.getImage()), out); } label.setText("Done."); } catch (Exception ioe) { MapTool.showInformation("AssetExtractor failure", ioe); } finally { if (pakfile != null) pakfile.close(); IOUtils.closeQuietly(r); IOUtils.closeQuietly(out); } } }.start(); }
From source file:ExcelComponents.FileOpener.java
public static File[] openfiles() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.addChoosableFileFilter(excelfilter); fileChooser.setMultiSelectionEnabled(true); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = fileChooser.getSelectedFiles().clone(); return (selectedFiles); }/* w w w . ja v a2s . c om*/ return null; }