List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java
private void exportPressed() { File chosenFile = null;// w w w . ja v a 2 s .c o m FileWriter fw = null; String title; if (cert != null) { title = res.getString("DViewCertCsrPem.ExportPemCertificate.Title"); } else { title = res.getString("DViewCertCsrPem.ExportPemCsr.Title"); } try { String certPem = jtaPem.getText(); JFileChooser chooser = FileChooserFactory.getX509FileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DViewCertCsrPem.ChooseExportFile.button")); if (rtnValue != JFileChooser.APPROVE_OPTION) { return; } chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); if (chosenFile.isFile()) { String message = MessageFormat.format(res.getString("DViewCertCsrPem.OverWriteFile.message"), chosenFile); int selected = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION); if (selected != JOptionPane.YES_OPTION) { return; } } fw = new FileWriter(chosenFile); fw.write(certPem); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DViewCertCsrPem.NoWriteFile.message"), chosenFile), title, JOptionPane.WARNING_MESSAGE); return; } catch (Exception ex) { DError.displayError(this, ex); return; } finally { IOUtils.closeQuietly(fw); } JOptionPane.showMessageDialog(this, res.getString("DViewCertCsrPem.ExportPemCertificateSuccessful.message"), title, JOptionPane.INFORMATION_MESSAGE); }
From source file:com.akman.excel.view.frmSelectImage.java
private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelectImageActionPerformed {//GEN-HEADEREND:event_btnSelectImageActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp"); chooser.setFileFilter(filter);/*from w w w. ja va 2 s . c o m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { //Saving file inside the file File file = chooser.getSelectedFile(); // if(!file.equals(filter)) // { // JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE); // return; // } //System.out.println(file.getAbsolutePath()); ImageIcon image = new ImageIcon(file.getAbsolutePath()); fileName = file.getAbsolutePath(); // Get Width And Height of PicLabel Rectangle rect = lblImage.getBounds(); //System.out.println(lblImage.getBounds()); //Scaling the image to fit in the picLabel Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel image = new ImageIcon(scaledimage); lblImage.setIcon(image); txtPath.setText(fileName); try { File images = new File(fileName); FileInputStream fis = new FileInputStream(images); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:com.enderville.enderinstaller.ui.Installer.java
private void chooseTargetMinecraftFolder() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); int opt = chooser.showOpenDialog(getMainPane()); if (opt == JFileChooser.APPROVE_OPTION) { File dir = chooser.getSelectedFile(); String oldDir = InstallerConfig.getMinecraftFolder(); InstallerConfig.setMinecraftFolder(dir.getAbsolutePath()); File mcjar = new File(InstallerConfig.getMinecraftJar()); if (!mcjar.exists()) { JOptionPane.showMessageDialog(getMainPane(), "The installer couldn't find a minecraft installation in the specified folder.\n" + "Restoring minecraft folder to " + oldDir, "Error setting target Minecraft installation", JOptionPane.ERROR_MESSAGE); InstallerConfig.setMinecraftFolder(oldDir); }/*from w ww . j av a 2s. co m*/ } }
From source file:org.martus.client.swingui.FxInSwingMainWindow.java
protected File[] showMultiFileOpenDialog(String title, File directory, Vector<FormatFilter> filters) { JFileChooser fileChooser = createFileChooser(title, directory, filters); fileChooser.setMultiSelectionEnabled(true); int userResult = fileChooser.showOpenDialog(getCurrentActiveFrame().getSwingFrame()); if (userResult != JFileChooser.APPROVE_OPTION) return new File[0]; return fileChooser.getSelectedFiles(); }
From source file:dotaSoundEditor.Controls.ItemPanel.java
@Override protected File promptUserForNewFile(String wavePath) { DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); String waveString = selectedTreeNode.getUserObject().toString(); String allowedExtension = FilenameUtils.getExtension(waveString).replace("\"", ""); JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = allowedExtension.equals("wav") ? new FileNameExtensionFilter("WAVs", "wav") : new FileNameExtensionFilter("MP3s", "mp3"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);// w w w. j a va 2 s .c o m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); int startIndex = -1; int endIndex = -1; //Get the actual value for the wavestring key-value pair. if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); String waveStringNormalizedFilePath = waveStringFilePath.substring(0, waveStringFilePath.lastIndexOf("\"")); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace(")", ""); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace("\"", ""); Path destPath = Paths.get(installDir, "/dota/sound/" + waveStringNormalizedFilePath); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); if (waveString.contains("//")) { waveString = waveString .replace(waveString.substring(waveString.indexOf("//"), waveString.length()), ""); } waveString = waveString.replace(waveStringFilePath, "\"" + waveStringNormalizedFilePath + "\" //Replaced by: " + chosenFile.getFileName().toString()); selectedTreeNode.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:com.apatar.ui.JPublishToApatarDialog.java
private void createListeners() { browse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir")); fileChooser.setMultiSelectionEnabled(false); int returnValue = fileChooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { File fileSrc = fileChooser.getSelectedFile(); nameFile.setText(fileSrc.getPath()); }/*ww w. j a v a 2 s . c om*/ } }); bCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { option = CANCEL_OPTION; setVisible(false); } }); bOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { option = OK_OPTION; setVisible(false); } }); selectFromFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (selectFromFile.isSelected()) { nameFile.setEnabled(true); browse.setEnabled(true); } else { nameFile.setEnabled(false); browse.setEnabled(false); } } }); autoGenerateShortDescription.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (autoGenerateShortDescription.isSelected()) setEnableShortDescription(false); else setEnableShortDescription(true); } }); }
From source file:uk.ac.ox.cbrg.cpfp.uploadapp.UploadApplet.java
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed // Create & show file chooser with extension filter as per applet param JFileChooser fc = new JFileChooser(); fc.setFileFilter(new CustomFileFilter(fileExtensions)); fc.setMultiSelectionEnabled(true); fc.showOpenDialog(UploadApplet.this); // Add selected files to upload queue File[] selFiles = fc.getSelectedFiles(); addFiles(selFiles);//from w ww. j a va2 s .co m }
From source file:my.swingconnect.SwingConnectUI.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //To BROWSE A FILE FROM THE DIRECTORY JFileChooser chooser = new JFileChooser(); //To enable showing hidden file chooser.setFileHidingEnabled(false); //To Enable selecting directory or files chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //To enable multiple file selections chooser.setMultiSelectionEnabled(true); //Choice of user to save or open a file chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle("Choose a file..."); //To user to select a file if (chooser.showOpenDialog(SwingConnectUI.this) == JFileChooser.APPROVE_OPTION) { targetFile = chooser.getSelectedFile(); String directory = targetFile.getPath(); jTextField4.setText(targetFile.toString()); // files = new File("/Users/pradil90/Desktop/207dropbox").listFiles(); files = new File(directory).listFiles(); for (File file : files) { if (file.isFile()) { results.add(file.getAbsolutePath()); // results.add(file.getName()); System.out.println(file); count++;//w ww .jav a2 s .c om System.out.println(count); } } results.remove(0); jButton3.setEnabled(true); } }
From source file:it.staiger.jmeter.protocol.http.config.gui.DynamicFilePanel.java
/** * Fills the table with the file parameters from the import settings panel */// w w w.j ava 2 s.com private void importFiles() { String relPath = folder.getText(); String replace = relPath + File.separator; if (relPath.isEmpty()) { relPath = FileDialoger.getLastJFCDirectory(); replace = ""; } JFileChooser chooser = new JFileChooser(new File(relPath)); chooser.setMultiSelectionEnabled(true); chooser.setDialogTitle("select files");// $NON-NLS-1$ if (chooser.showOpenDialog(GuiPackage.getInstance().getMainFrame()) == JFileChooser.APPROVE_OPTION) { File[] files = chooser.getSelectedFiles(); for (File file : files) { String path = file.getAbsolutePath().replace(replace, ""); String name = file.getName(); int last = name.lastIndexOf("."); if (last != -1) name = name.substring(0, last); HTTPFileArg hFile = new HTTPFileArg(path, name, attachmentsCT.getText()); addFile(hFile); } FileDialoger.setLastJFCDirectory(files[0].getAbsolutePath()); } }
From source file:com.akman.excel.view.frmExportExcel.java
private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectImageActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp"); chooser.setFileFilter(filter);/*from w w w . j av a 2s . c o m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { //Saving file inside the file File file = chooser.getSelectedFile(); // if(!file.equals(filter)) // { // JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE); // return; // } //System.out.println(file.getAbsolutePath()); ImageIcon image = new ImageIcon(file.getAbsolutePath()); fileNameSignature = file.getAbsolutePath(); // Get Width And Height of PicLabel Rectangle rect = lblImage.getBounds(); //System.out.println(lblImage.getBounds()); //Scaling the image to fit in the picLabel Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel image = new ImageIcon(scaledimage); lblImage.setIcon(image); txtPathSig.setText(fileNameSignature); try { File images = new File(fileNameSignature); FileInputStream fis = new FileInputStream(images); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }