List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
private boolean chooseDirectory(JTextField textField) { JFileChooser fileOpen = new JFileChooser(); fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileOpen.showOpenDialog(this); boolean directoryChoosed = false; if (fileOpen.getSelectedFile() != null) { File directory = new File(fileOpen.getSelectedFile().getAbsolutePath()); textField.setText(directory.getPath()); resultFiles = getFilesOnDirectory(directory); directoryChoosed = true;/* ww w . jav a2 s . c o m*/ } // Codigo para Mac OSX // FileDialog fileopen = new FileDialog(this, "Open Results Directory", FileDialog.LOAD); // fileopen.setModalityType(ModalityType.DOCUMENT_MODAL); // // System.setProperty("apple.awt.fileDialogForDirectories", "true"); // fileopen.setVisible(true); // System.setProperty("apple.awt.fileDialogForDirectories", "false"); // // if (fileopen.getFile() != null) { // File directory = new File(fileopen.getDirectory(), fileopen.getFile()); // textField.setText(directory.getPath()); // // resultFiles = getFilesOnDirectory(directory); // // List<File> foundFiles = ; // // for (File file : foundFiles) { // // if (file.getName().endsWith(".txt")) { // // resultFiles.add(file); // // } // // } // directoryChoosed = true; // } return directoryChoosed; }
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 w w. ja v a2 s .c o m } }
From source file:com.swg.parse.docx.OpenWord.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setAcceptAllFileFilterUsed(false); //this authorize only .docx selection fc.addChoosableFileFilter(new DocxFileFilter()); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }//from ww w .j av a 2 s. com int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); String zipFilePath = "C:\\Users\\KXK3\\Documents\\ZipTest\\test.zip"; String destDirectory = "C:\\Users\\KXK3\\Documents\\ZipTest\\temp"; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(selectedFile, zip); unzipper.UnzipUtility(zip, directory); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\KXK3\\Documents\\ZipTest\\Pictures\\" + fil.getName())); } zip.delete(); FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content; String POIContent; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, selectedFile.getAbsolutePath(), version, 1); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } } else { //do nothing } }
From source file:com._17od.upm.gui.OptionsDialog.java
private void getDBToLoadOnStartup() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.translate("dbToOpenOnStartup")); int returnVal = fc.showOpenDialog(parentFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File databaseFile = fc.getSelectedFile(); dbToLoadOnStartup.setText(databaseFile.getAbsoluteFile().toString()); }//from ww w . j ava 2 s .c o m }
From source file:Compare.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);/*from w w w. j a v a2s . c o m*/ int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); } listofFiles(myfolder); sortByName(); DefaultTableModel model = (DefaultTableModel) FileDetails.getModel(); int count = 1; for (Files filename : filenames1) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:pl.dpbz.poid.zadanie4.gui.GUI.java
private void saveJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveJButtonActionPerformed // TODO save sound to file JFileChooser fc = new JFileChooser(); fc.showSaveDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); path += ".wav"; SamplesToWave saver;//from w w w . j av a2 s . c o m if (this.wahWahJRadioButton.isSelected()) { saver = new SamplesToWave(44100, this.filterWahWah.getOutputSignal(), this.af); } else { saver = new SamplesToWave(SOIFilter.SAMPLING_FREQUENCY, this.filter.getOutputSignal(), this.af); } try { saver.saveWave(path); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Zapisane"); }
From source file:datavis.Gui.java
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed //The action to select a file //By opening a pop-up containing a file browser javax.swing.JFileChooser choose = new javax.swing.JFileChooser(); choose.showOpenDialog(null);/* w ww. java 2s . c o m*/ File f = choose.getSelectedFile(); String fileHandle = f.getAbsolutePath(); System.out.println(fileHandle); // jComboBox1.removeAllItems(); // jComboBox2.removeAllItems(); // jComboBox3.removeAllItems(); try { dataset = new DataList_PWL_SURGE_ATP_WTP_WSD_BPR(fileHandle); } catch (UnsupportedEncodingException ex) { JOptionPane.showMessageDialog(null, "The data file you selected is not supported."); return; } //Set the text of the button to the file handle absolute pathname button1.setLabel(fileHandle); //update all graphs updateGraphs_pieChart(dataset, true); updateGraphs_barGraph(dataset, true); updateGraphs_lineGraph(dataset, true); //get the drop down menu items from the dataset class String sampleTypes[] = dataset.getDropMenu(); //fill the node text area with all the node information jTextArea1.setText(dataset.toString()); jTextArea1.setCaretPosition(0); //fill the status text area with station and developer info jTextArea2.setText(dataset.getStationInfo() + displayDevelopers); jTextArea2.setCaretPosition(0); //clear the combobox for (int i = 0; i < jComboBox1.getItemCount(); i++) { jComboBox1.remove(i); jComboBox2.remove(i); jComboBox3.remove(i); } //Add each sample type to the drop-down combobox for (int i = 0; i < sampleTypes.length; i++) { jComboBox1.addItem(sampleTypes[i]); jComboBox2.addItem(sampleTypes[i]); jComboBox3.addItem(sampleTypes[i]); } }
From source file:Compare.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);/*w w w .j a v a 2 s . co m*/ int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); listofFiles1(myfolder); sortByName1(); } DefaultTableModel model = (DefaultTableModel) FileDetails1.getModel(); int count = 1; System.out.println(filenames2.size()); for (Files filename : filenames2) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:ru.develgame.jflickrorganizer.MainForm.java
private void jButtonChooseBackupFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChooseBackupFolderActionPerformed JFileChooser jFileChooserSaveBackup = new JFileChooser(); jFileChooserSaveBackup.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = jFileChooserSaveBackup.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { jTextFieldBackupFolder.setText(jFileChooserSaveBackup.getSelectedFile().getAbsolutePath()); }/* w w w .j a v a2 s . co m*/ }
From source file:com.josue.tileset.editor.Editor.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("Image file", "png")); fileDialog.showOpenDialog(null);/* w w w .j a v a2 s. c o m*/ inputFile = fileDialog.getSelectedFile(); if (inputFile != null) { loadFile(inputFile); } }