List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:Main.java
public Main() throws Exception { JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null);// ww w . ja v a 2s . c om soundFile = chooser.getSelectedFile(); System.out.println("Playing " + soundFile.getName()); Line.Info linfo = new Line.Info(Clip.class); Line line = AudioSystem.getLine(linfo); clip = (Clip) line; clip.addLineListener(this); AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile); clip.open(ais); clip.start(); }
From source file:com.sciaps.utils.Util.java
public static ArrayList<SpectrumShotItem> readCSVFile() { ArrayList<SpectrumShotItem> shotItems = new ArrayList<SpectrumShotItem>(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("CSV files", "csv", "CSV")); int retrival = chooser.showOpenDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { ProgressStatusPanel progressbar = new ProgressStatusPanel(); final CustomDialog progressDialog = new CustomDialog(Constants.MAIN_FRAME, "Importing CSV file", progressbar, CustomDialog.NONE_OPTION); progressDialog.setSize(400, 100); SwingUtilities.invokeLater(new Runnable() { @Override//from www .j a v a2s.c o m public void run() { progressDialog.setVisible(true); } }); try { FileReader fr = new FileReader(chooser.getSelectedFile()); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { shotItems.add(packSpectrumShotItem(line)); } br.close(); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Exception: " + ex.getMessage()); } progressDialog.dispose(); } return shotItems; }
From source file:ActionListenerTest2.java
public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.print(fileChooser.getSelectedFile().getName()); }// ww w. j a va2 s .c o m }
From source file:GuardarImagen.AyudaParaImagen.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: JFileChooser selector = new JFileChooser(); selector.showOpenDialog(this); File file = selector.getSelectedFile(); try {//from w w w . j av a 2 s .c o m FileInputStream fis = new FileInputStream(file); byte[] datosImagen = IOUtils.toByteArray(fis); Galeria g1 = new Galeria(); g1.setDatosImagen(datosImagen); g1.setDescripcion("Porno 1"); g1.setTitulo("Madonna"); PersistenciaGaleria p = new PersistenciaGaleria(); p.guardar(g1); } catch (Exception e) { } }
From source file:Main.java
protected void saveToFile() { JFileChooser fileChooser = new JFileChooser(); int retval = fileChooser.showSaveDialog(save); if (retval == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (file == null) { return; }//from w w w .j a va 2s .co m if (!file.getName().toLowerCase().endsWith(".txt")) { file = new File(file.getParentFile(), file.getName() + ".txt"); } try { textArea.write(new OutputStreamWriter(new FileOutputStream(file), "utf-8")); Desktop.getDesktop().open(file); } catch (Exception e) { e.printStackTrace(); } } }
From source file:Main.java
/** * Displays a {@link JFileChooser} to select a file. * * @param title The title of the dialog. * @param startDirectory The directory where the dialog is initialed opened. * @param fileExtension File extension to filter each content of the opened * directories. Example ".xml".//from w w w . ja va2 s . c o m * @param startFile The preselected file where the dialog is initialed opened. * @return The {@link File} object selected, returns null if no file was selected. */ public static File chooseFile(String title, String startDirectory, final String fileExtension, String startFile) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(title); if (fileExtension != null && !fileExtension.trim().equals("")) { FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() || pathname.getName().endsWith(fileExtension); } @Override public String getDescription() { return "(" + fileExtension + ")"; } }; chooser.setFileFilter(filter); } if (startDirectory != null && !startDirectory.trim().equals("")) { chooser.setCurrentDirectory(new File(startDirectory)); } if (startFile != null && !startFile.trim().equals("")) { chooser.setSelectedFile(new File(startFile)); } int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; }
From source file:sample.fa.ScriptRunnerApplication.java
private void loadScript(ActionEvent ae) { JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(scriptContents);/*from w ww . j av a 2 s . c o m*/ if (jfc.getSelectedFile() != null) { loadScript(jfc.getSelectedFile()); } }
From source file:sample.fa.ScriptRunnerApplication.java
private void saveScript(ActionEvent ae) { JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(scriptContents);//from w w w .j av a 2 s. c om File f = jfc.getSelectedFile(); if (f != null) { try { Files.write(f.toPath(), scriptContents.getText().getBytes()); } catch (IOException ex) { JOptionPane.showMessageDialog(scriptContents, ex.getMessage(), "Error Saving Script", JOptionPane.ERROR_MESSAGE); } } }
From source file:ImageFileFilterImageScale.java
private String getImageFile() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new ImageFilter()); int result = fc.showOpenDialog(null); File file = null;/*from w w w .j a va 2s . c o m*/ if (result == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); return file.getPath(); } else return null; }
From source file:de.jcup.egradle.other.GroovyParserSourceCollector.java
private void start(String[] args) throws IOException { File groovyProjectDirectory;/*from ww w. j a v a 2s . c o m*/ if (args.length == 0) { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(null); groovyProjectDirectory = fc.getSelectedFile(); } else { groovyProjectDirectory = new File(args[0]); } if (groovyProjectDirectory == null) { System.err.println("canceled"); System.exit(1); } System.out.println("use groovy sources at:" + groovyProjectDirectory.getAbsolutePath()); assertDirectoryExists(groovyProjectDirectory); File groovyTempDirectory = new File(groovyProjectDirectory, "/target/tmp/groovydoc"); File target = new File("./..//egradle-plugin-main/src/main/java-groovy"); assertDirectoryExists(target); execute(groovyTempDirectory, target); System.out.println("DONE"); }