JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File("fileToSave.txt")); jFileChooser.showSaveDialog(parent);
public void actionPerformed(ActionEvent ae) { final JFileChooser jfc = new JFileChooser(); final int response = jfc.showOpenDialog(LexerFrame.this); if (response != JFileChooser.APPROVE_OPTION) { return; } safeScanScript(jfc.getSelectedFile()); } };
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfSoxPath.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseSoxActionPerformed
/** * Do the stuff for this class (create the file) * * @throws Exception */ public static void main(String args[]) throws Exception { System.out.println("Starting..."); String wd = "./test"; // choose the directory to open JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(wd)); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File[] dirs = chooser.getSelectedFiles(); for (File directory : dirs) { System.out.println("Doing migration on directory: " + directory.getAbsolutePath()); doMigration(directory); } } }
private static JFileChooser createFileChooser() { final JFileChooser chooser = new JFileChooser(); // sets up default file view try { chooserFile = new File((new File(".").getCanonicalPath())); } catch (Exception e) { // go with current directory. } chooser.setCurrentDirectory(chooserFile); chooser.addActionListener(e -> { if(e.getActionCommand().equals("ApproveSelection")) { chooserFile = chooser.getSelectedFile(); } }); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); return chooser; }
file = new File(filename); url = new File(args[1]).toURI().toURL(); } else { url = AudioTool.class.getResource("spectrogram.config.xml"); fileChooser = new JFileChooser(); createMenuBar(jframe);
import javax.swing.JFileChooser; javax.swing.filechooser.FileSystemView; public class GetMyDocuments { public static void main(String args[]) { JFileChooser fr = new JFileChooser(); FileSystemView fw = fr.getFileSystemView(); System.out.println(fw.getDefaultDirectory()); } }
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(rootDirectoryField.getText()); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.showDialog(frame, "Select"); if (fc.getSelectedFile() != null) { rootDirectoryField.setText(fc.getSelectedFile().getAbsolutePath()); } } }
public static File showSaveDialog(String[] exts) { JFileChooser dialog = new JFileChooser(); if (exts != null) { dialog.setFileFilter(new ExtensionFilter(exts)); } int returnVal = dialog.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { return dialog.getSelectedFile(); } return null; }
JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(frame); File[] files = chooser.getSelectedFiles(); if(files.length >= 2) { compare(readFileAsList(files[0]), readFileAsList(files[1])); }
JFileChooser saveFile = new JFileChooser(); saveFile.showSaveDialog(null); JFileChooser openFile = new JFileChooser(); openFile.showOpenDialog(null);
private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem_OpenActionPerformed // Allow user to choose a different voice (prompt set) without exiting the tool // Create a file chooser final JFileChooser openDialog = new JFileChooser(); // Set the current directory to the voice currently in use openDialog.setCurrentDirectory(getVoiceFolderPath()); openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = openDialog.showDialog(AdminWindow.this, "Open Voice"); if (result == JFileChooser.APPROVE_OPTION) { File voice = openDialog.getSelectedFile(); setVoiceFolderPath(voice); // Set to the selected the voice folder path Test.output("Open voice: " + voice); setupVoice(); } else { Test.output("Open command cancelled."); } }// GEN-LAST:event_jMenuItem_OpenActionPerformed
JFileChooser j = new JFileChooser(); j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); Integer opt = j.showSaveDialog(this);
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfSoxPath.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseSoxActionPerformed
public void openFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(true); String[] exts = {"apk", "dex", "jar", "class", "zip", "aar", "arsc"}; String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')'); fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts)); fileChooser.setToolTipText(NLS.str("file.open_action")); String currentDirectory = settings.getLastOpenFilePath(); if (!currentDirectory.isEmpty()) { fileChooser.setCurrentDirectory(new File(currentDirectory)); } int ret = fileChooser.showDialog(mainPanel, NLS.str("file.open_title")); if (ret == JFileChooser.APPROVE_OPTION) { settings.setLastOpenFilePath(fileChooser.getCurrentDirectory().getPath()); openFile(fileChooser.getSelectedFile()); } }
JFileChooser chooser = new JFileChooser( new File(".") ) { public void approveSelection() { if (getSelectedFile().isFile()) { // beep return; } else super.approveSelection(); } };
/** * Uses a JFileChooser to select a file to opened with the * LF5 GUI. */ protected void requestOpen() { JFileChooser chooser; if (_fileLocation == null) { chooser = new JFileChooser(); } else { chooser = new JFileChooser(_fileLocation); } int returnVal = chooser.showOpenDialog(_logMonitorFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); if (loadLogFile(f)) { _fileLocation = chooser.getSelectedFile(); _mruFileManager.set(f); updateMRUList(); } } }
@Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); boolean cont = chooser.showSaveDialog(SpoonModelTree.this) == JFileChooser.APPROVE_OPTION; if (cont) { SerializationModelStreamer ser = new SerializationModelStreamer(); try { ser.save(factory, new FileOutputStream(chooser .getSelectedFile())); } catch (IOException e1) { Launcher.LOGGER.error(e1.getMessage(), e1); } } } });
JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(frame); File[] files = chooser.getSelectedFiles();
private void browseInputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseInputDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfInputDir.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseInputDirActionPerformed