List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * Gets the show to open and opens the respective json file. *///from w ww . j a v a2 s .c om private void openShow() { if (askToSave()) { File file; final JFileChooser fc = new JFileChooser(Main.getFilePath()); fc.setFileFilter(new DrillFileFilter()); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal; do { returnVal = fc.showOpenDialog(this); file = fc.getSelectedFile(); } while (returnVal != JFileChooser.CANCEL_OPTION && returnVal != JFileChooser.ERROR_OPTION && !file.exists()); if (returnVal == JFileChooser.APPROVE_OPTION) { try { String name, path; path = file.getCanonicalPath(); path = path.substring(0, Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/')) + 1); name = file.getName().toLowerCase().endsWith(".drill") ? file.getName() : file.getName() + ".drill"; Main.setFilePath(path); Main.setPagesFileName(name); Main.load(false); desktop.createNewInternalFrames(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:maltcms.ui.nb.pipelineRunner.options.LocalMaltcmsExecutionPanel.java
private void selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectActionPerformed FileChooserBuilder fcb = new FileChooserBuilder(LocalMaltcmsExecutionPanel.class); fcb.setFilesOnly(false);/*from ww w .jav a 2 s. c o m*/ fcb.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } return file.getName().equals("maltcms.jar"); } @Override public String getDescription() { return "maltcms.jar"; } }); fcb.setSelectionApprover(new FileChooserBuilder.SelectionApprover() { @Override public boolean approve(File[] files) { // boolean approve = false; for (File f : files) { if (f.getName().equals("maltcms.jar")) { return true; } } return false; } }); JFileChooser jfc = fcb.createFileChooser(); if (!maltcmsInstallationPath.getText().isEmpty()) { File basedir = new File(maltcmsInstallationPath.getText()); jfc.setCurrentDirectory(basedir); } int ret = jfc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); maltcmsInstallationPath.setText(f.getParent()); checkVersion(f.getParentFile().getAbsolutePath()); controller.changed(); } }
From source file:Forms.FrmPrincipal.java
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed // TODO add your handling code here: File sArchivo;/*from ww w .j a v a 2 s .c o m*/ JFileChooser archivo = new JFileChooser(); BufferedReader br = null; int lin = 0; patrones = new ArrayList<String[]>(); try { archivo.setCurrentDirectory(new File(System.getProperty("user.home"))); int result = archivo.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { sArchivo = archivo.getSelectedFile(); txtArchivo.setText(sArchivo.getAbsolutePath()); br = new BufferedReader(new FileReader(sArchivo.getAbsolutePath())); String linea = br.readLine(); while (null != linea) { String[] campos = linea.split(SEPARADOR); numEntradas = campos.length; patrones.add(campos); linea = br.readLine(); lin++; } } llenaMatriz(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex); } finally { if (null != br) try { br.close(); } catch (IOException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:androhashcheck.MainFrame.java
/** * Opens file expolorer to choose file to be uploaded. * * @param evt//from ww w . j a va 2 s. c o m */ private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println("Selected file: " + selectedFile.getAbsolutePath()); this.textField1.setText(selectedFile.getAbsolutePath()); } }
From source file:com.josue.tileset.editor.Editor.java
private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBtnActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("Json file", "json")); String outputFileName = inputFile.getAbsolutePath().split("\\.")[0] + ".json"; fileDialog.setSelectedFile(new File(outputFileName)); if (fileDialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File file = fileDialog.getSelectedFile(); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); try {// w ww.ja v a 2 s . co m mapper.writeValue(file, loadedTiles); } catch (IOException ex) { Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * Creates a new json file for a new show * * @throws InterruptedException if there is an error when waiting for the saves to finish */// w ww . j a v a2s . co m private void newShow() throws InterruptedException { if (askToSave()) { final JFileChooser fc = new JFileChooser(new File(Main.getFilePath())); fc.setFileFilter(new DrillFileFilter()); int returnVal = fc.showDialog(this, "New File"); String name, path; if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fc.getSelectedFile(); path = file.getCanonicalPath(); path = path.substring(0, Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/')) + 1); name = file.getName().toLowerCase().endsWith(".drill") ? file.getName() : file.getName() + ".drill"; Main.setFilePath(path); Main.setPagesFileName(name); Main.saveState().join(); Main.load(false); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.sf.energy.transfer.form.DataConfiguration.java
/** * ??//from ww w .j a v a 2 s .c om * @param evt ? */ private void scanActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser fc = new JFileChooser(); File directory = new File(dir); // ?? fc.setCurrentDirectory(directory); fc.setDialogTitle(""); // FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls"); fc.addChoosableFileFilter(filter1); FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp"); fc.addChoosableFileFilter(filter1); // fc.setFileFilter(fc.getAcceptAllFileFilter()); int intRetVal = fc.showOpenDialog(new JFrame()); // ? if (intRetVal == JFileChooser.APPROVE_OPTION) { // ? dir = fc.getSelectedFile().getPath(); // filePath.setText(dir); } }
From source file:au.org.ala.delta.editor.ui.image.ImageSettingsDialog.java
@Action public void addToImagePath() { JFileChooser chooser = new JFileChooser(_imageSettings.getDataSetPath()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = chooser.showDialog(this, _resources.getString("okImageSettingsChanges.Action.text")); if (result == JFileChooser.APPROVE_OPTION) { _imageSettings.addToResourcePath(chooser.getSelectedFile()); imagePathTextField.setText(_imageSettings.getResourcePath()); }// w w w .j a va 2 s . c o m }
From source file:filterviewplugin.FilterViewSettingsTab.java
private void chooseIcon(final String filterName) { String iconPath = mIcons.get(filterName); JFileChooser chooser = new JFileChooser( iconPath == null ? new File("") : (new File(iconPath)).getParentFile()); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); String msg = mLocalizer.msg("iconFiles", "Icon Files ({0})", "*.png,*.jpg, *.gif"); String[] extArr = { ".png", ".jpg", ".gif" }; chooser.setFileFilter(new ExtensionFileFilter(extArr, msg)); chooser.setDialogTitle(mLocalizer.msg("chooseIcon", "Choose icon for '{0}'", filterName)); Window w = UiUtilities.getLastModalChildOf(FilterViewPlugin.getInstance().getSuperFrame()); if (chooser.showDialog(w, Localizer.getLocalization(Localizer.I18N_SELECT)) == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File dir = new File(FilterViewSettings.getIconDirectoryName()); if (!dir.isDirectory()) { dir.mkdir();//from w w w. j a v a 2s . c o m } String ext = chooser.getSelectedFile().getName(); ext = ext.substring(ext.lastIndexOf('.')); Icon icon = FilterViewPlugin.getInstance().getIcon(chooser.getSelectedFile().getAbsolutePath()); if (icon.getIconWidth() > MAX_ICON_WIDTH || icon.getIconHeight() > MAX_ICON_HEIGHT) { JOptionPane.showMessageDialog(w, mLocalizer.msg("iconSize", "The icon size must be at most {0}x{1}.", MAX_ICON_WIDTH, MAX_ICON_HEIGHT)); return; } try { IOUtilities.copy(chooser.getSelectedFile(), new File(dir, filterName + ext)); } catch (IOException e1) { e1.printStackTrace(); } mIcons.put(filterName, filterName + ext); mFilterList.updateUI(); } } }
From source file:firmadigital.Firma.java
private void cmdExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarActionPerformed JFileChooser fileChooser = new JFileChooser(); txtUbicacion.setText(""); lblNombreArchivo.setText(""); lblRutaArchivo.setText(""); String signFileName = txtUbicacion.getText(); File directory = new File(signFileName).getParentFile(); fileChooser.setCurrentDirectory(directory); FileNameExtensionFilter filter; filter = new FileNameExtensionFilter("XML file", "xml"); fileChooser.setFileFilter(filter);//from www . j a va2 s . co m fileChooser.setFileHidingEnabled(true); /*Remove All File option*/ fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacion.setText(selectedFile); lblNombreArchivo.setText(fileChooser.getSelectedFile().getName()); lblRutaArchivo.setText(fileChooser.getSelectedFile().getParent()); } }