List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:colectordedatos.resultados.java
private void Exportar_a_ExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exportar_a_ExcelActionPerformed if (jTable1.getRowCount() > 0) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de excel", "xls"); chooser.setFileFilter(filter);//from w w w. j a v a 2s . c o m chooser.setDialogTitle("Guardar archivo"); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { List<JTable> tb = new ArrayList<JTable>(); List<String> nom = new ArrayList<String>(); tb.add(jTable1); nom.add("Reporte de Errores"); String file = chooser.getSelectedFile().toString().concat(".xls"); try { exportaraexcel e = new exportaraexcel(new File(file), tb, nom); if (e.export()) { JOptionPane.showMessageDialog(null, "Los datos fueron exportados a excel en el directorio seleccionado", "Mensaje de Informacion", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Hubo un error " + e.getMessage(), " Error", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(this, "No hay datos para exportar", "Mensaje de error", JOptionPane.ERROR_MESSAGE); } }
From source file:cool.pandora.modeller.ui.handlers.base.AddDataHandler.java
/** * addData.// w ww . j av a 2 s .co m */ void addData() { final File selectFile = new File(File.separator + "."); final JFrame frame = new JFrame(); final JFileChooser fc = new JFileChooser(selectFile); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setDialogTitle("Add File or Directory"); final int option = fc.showOpenDialog(frame); if (option == JFileChooser.APPROVE_OPTION) { final File[] files = fc.getSelectedFiles(); final String message = ApplicationContextUtil.getMessage("bag.message.filesadded"); if (files != null && files.length > 0) { addBagData(files); ApplicationContextUtil.addConsoleMessage(message + " " + getFileNames(files)); } else { final File file = fc.getSelectedFile(); addBagData(file); ApplicationContextUtil.addConsoleMessage(message + " " + file.getAbsolutePath()); } bagView.bagPayloadTreePanel.refresh(bagView.bagPayloadTree); bagView.updateAddData(); } }
From source file:com.mycompany.zad1.MainWindow.java
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed JFileChooser chooser = new JFileChooser(); int dialogResult = chooser.showSaveDialog(this); if (dialogResult == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try {//from w w w. jav a 2 s . c o m imageInOut.saveImageToFile(imageBuff, file, "bmp"); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.martus.client.swingui.FxInSwingMainWindow.java
protected File showFileSaveDialog(String title, File directory, Vector<FormatFilter> filters) { while (true) { JFileChooser fileChooser = createFileChooser(title, directory, filters); int userResult = fileChooser.showSaveDialog(getCurrentActiveFrame().getSwingFrame()); if (userResult != JFileChooser.APPROVE_OPTION) return null; File selectedFile = fileChooser.getSelectedFile(); FormatFilter selectedFilter = (FormatFilter) fileChooser.getFileFilter(); selectedFile = getFileWithExtension(selectedFile, selectedFilter.getExtension()); if (!selectedFile.exists()) return selectedFile; if (confirmDlg(getCurrentActiveFrame().getSwingFrame(), "OverWriteExistingFile")) return selectedFile; directory = selectedFile.getParentFile(); }//from w ww. jav a2 s .c o m }
From source file:com.moneydance.modules.features.importlist.io.DefaultDirectoryChooser.java
@Override void chooseBaseDirectory() { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(this.getLocalizable().getDirectoryChooserTitle()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // disable the "All files" option. fileChooser.setAcceptAllFileFilterUsed(false); try {/*from www .jav a 2 s . c om*/ fileChooser.setCurrentDirectory(FileUtils.getUserDirectory()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); fileChooser.setCurrentDirectory(parentDirectory); } if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } this.getPrefs().setBaseDirectory(fileChooser.getSelectedFile().getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:coreferenceresolver.gui.MainGUI.java
private void applyClassifierBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyClassifierBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose where your classified result file saved"); inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { resultFilePathTF1.setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "classified_result.txt"); noteTF.setText("Create classified result file waiting ..."); new Thread(new Runnable() { @Override/* w w w . j a v a2 s . c o m*/ public void run() { try { WekaMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(), trainingFilePathTF.getText(), testingFilePathTF.getText(), resultFilePathTF1.getText()); noteTF.setText("Create result file done!"); String folderPathOpen = resultFilePathTF1.getText().substring(0, resultFilePathTF1.getText().lastIndexOf(File.separatorChar)); Desktop.getDesktop().open(new File(folderPathOpen)); //Open the window for predicted chains ClassifiedResultGUI.render(true); //Open the window for actual chains ClassifiedResultGUI.render(false); } catch (Exception ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } else { noteTF.setText("No classified result file location selected"); } }
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * Saves the current file under a new name/path * * @throws InterruptedException if there is an error when waiting for the saves to finish *//*from w w w. j a v a 2s. co m*/ private void saveAs() throws InterruptedException { if (askToSave()) { final JFileChooser fc = new JFileChooser(Main.getFilePath()); fc.setFileFilter(new DrillFileFilter()); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showSaveDialog(this); File file = fc.getSelectedFile(); String name, path; if (returnVal == JFileChooser.APPROVE_OPTION) { try { 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.savePages().join(); Main.saveState().join(); Main.load(false); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.jvms.i18neditor.Editor.java
public void showImportDialog() { String path = null;//from w w w. java2s . c o m if (resourcesDir != null) { path = resourcesDir.toString(); } JFileChooser fc = new JFileChooser(path); fc.setDialogTitle(MessageBundle.get("dialogs.import.title")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { importResources(Paths.get(fc.getSelectedFile().getPath())); } }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Choose the directory and load its data into a given JTree. * * @param dataTree//from w w w .j a v a 2 s . co m */ private void chooseDirectoryAndLoadData() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Please select a root folder containing your files"); // allow for directories only fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // removing "All Files" option from FileType fileChooser.setAcceptAllFileFilterUsed(false); int returnVal = fileChooser.showOpenDialog(cellCoordController.getCellCoordFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { // the directory for the data directory = fileChooser.getSelectedFile(); try { loadDataIntoTree(); } catch (LoadDirectoryException ex) { LOG.error(ex.getMessage()); cellCoordController.showMessage(ex.getMessage(), "wrong directory structure error", JOptionPane.ERROR_MESSAGE); } } else { cellCoordController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:coreferenceresolver.gui.MainGUI.java
private void testBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose where your testing file saved"); inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { testingFilePathTF/*from w ww . j a v a 2 s . co m*/ .setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "test.arff"); noteTF.setText("Create testing file waiting ..."); new Thread(new Runnable() { @Override public void run() { try { TrainingMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(), testingFilePathTF.getText(), false); noteTF.setText("Create testing file done!"); String folderPathOpen = testingFilePathTF.getText().substring(0, testingFilePathTF.getText().lastIndexOf(File.separatorChar)); Desktop.getDesktop().open(new File(folderPathOpen)); } catch (Exception ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } else { noteTF.setText("No testing file location selected"); } }