import javax.swing.*; public class Example { public static void main(String[] args) { JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.showSaveDialog(null); System.out.println(f.getCurrentDirectory()); System.out.println(f.getSelectedFile()); } }
private void saveCurrentDir() { File dir = super.getCurrentDirectory(); if (!DONT_STORE_DIRECTORIES && dir != null && dir.exists() && dir.isDirectory()) { NbPreferences.forModule(FileChooserBuilder.class).put(dirKey, dir.getPath()); } } }
private void saveOpenDialogDir(JFileChooser fc) { try { File currentDir = fc.getCurrentDirectory(); if (currentDir != null && currentDir.exists() && currentDir.isDirectory()) { luytenPrefs.setFileOpenCurrentDirectory(currentDir.getAbsolutePath()); } } catch (Exception e) { Luyten.showExceptionDialog("Exception!", e); } }
private void saveSaveDialogDir(JFileChooser fc) { try { File currentDir = fc.getCurrentDirectory(); if (currentDir != null && currentDir.exists() && currentDir.isDirectory()) { luytenPrefs.setFileSaveCurrentDirectory(currentDir.getAbsolutePath()); } } catch (Exception e) { Luyten.showExceptionDialog("Exception!", e); } } }
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()); } }
/** * Show an open dialog with a file chooser set up according to the * parameters of this builder. * @return A file if the user clicks the accept button and a file or * folder was selected at the time the user clicked cancel. */ public File showOpenDialog() { JFileChooser chooser = createFileChooser(); if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() ); if( null != fileDialog ) { return showFileDialog(fileDialog, FileDialog.LOAD ); } } chooser.setMultiSelectionEnabled(false); int dlgResult = chooser.showOpenDialog(findDialogParent()); if (JFileChooser.APPROVE_OPTION == dlgResult) { File result = chooser.getSelectedFile(); if (result != null && !result.exists()) { result = null; } return result; } else { return null; } }
/** * Show a save dialog with the file chooser set up according to the * parameters of this builder. * @return A file if the user clicks the accept button and a file or * folder was selected at the time the user clicked cancel. */ public File showSaveDialog() { JFileChooser chooser = createFileChooser(); if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() ); if( null != fileDialog ) { return showFileDialog( fileDialog, FileDialog.SAVE ); } } int result = chooser.showSaveDialog(findDialogParent()); if (JFileChooser.APPROVE_OPTION == result) { return chooser.getSelectedFile(); } else { return null; } }
+ chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
private void saveAll(boolean export) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setToolTipText(NLS.str("file.save_all_msg")); String currentDirectory = settings.getLastSaveFilePath(); if (!currentDirectory.isEmpty()) { fileChooser.setCurrentDirectory(new File(currentDirectory)); } int ret = fileChooser.showDialog(mainPanel, NLS.str("file.select")); if (ret == JFileChooser.APPROVE_OPTION) { JadxArgs decompilerArgs = wrapper.getArgs(); decompilerArgs.setExportAsGradleProject(export); if (export) { decompilerArgs.setSkipSources(false); decompilerArgs.setSkipResources(false); } else { decompilerArgs.setSkipSources(settings.isSkipSources()); decompilerArgs.setSkipResources(settings.isSkipResources()); } settings.setLastSaveFilePath(fileChooser.getCurrentDirectory().getPath()); ProgressMonitor progressMonitor = new ProgressMonitor(mainPanel, NLS.str("msg.saving_sources"), "", 0, 100); progressMonitor.setMillisToPopup(0); wrapper.saveAll(fileChooser.getSelectedFile(), progressMonitor); } }
JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("choosertitle"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); } else { System.out.println("No Selection "); }
/** * Displays a file chooser dialog and returns the selected file. * * @return the selected file */ static File getFile() { JFileChooser chooser = new JFileChooser(cwd); chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File f) { return true; } @Override public String getDescription() { return "All files"; } }); if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) { return null; } cwd = chooser.getCurrentDirectory(); return chooser.getSelectedFile(); } }
/** * gets the directory to use in the file dialog. * * @return the directory of the file dialog. */ public String getDirectory() { return fileChooser.getCurrentDirectory().getPath(); }
JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); File selected = fc.getSelectedFile(); System.out.println("You selected " + selected); File currentDirectory = fc.getCurrentDirectory(); // Hack alert fc.setSelectedFile(new File("")); fc.setCurrentDirectory(currentDirectory); fc.showOpenDialog(null); selected = fc.getSelectedFile(); System.out.println("You selected " + selected);
@Override public void savePreferences() { final File currentDirectory = this.fileChooser.getCurrentDirectory(); if (currentDirectory == null) { return; } this.preferences.put("folder", currentDirectory.getAbsolutePath()); //$NON-NLS-1$ }
@Override public void savePreferences() { final File currentDirectory = this.fileChooser.getCurrentDirectory(); this.preferences.put("folder", currentDirectory.getAbsolutePath()); //$NON-NLS-1$ }
public void actionPerformed(final ActionEvent _ae) { final String s = _f.getCurrentDirectory().getAbsolutePath(); if (!list_.contains(s)) { model.addElement(s); CtuluFavoriteFiles.this.fireChange(); } } });
public void rescanCurrentDirectory(JFileChooser fc) { super.rescanCurrentDirectory(fc); findFile(chooser.getSelectedFile() == null?chooser.getCurrentDirectory() :chooser.getSelectedFile(), true, true); }
public DirectoryComboBoxModel() { // Add the current directory to the model, and make it the // selectedDirectory File dir= getFileChooser().getCurrentDirectory(); if (dir != null) { addItem(dir); } }
@Test public void testGetCurrentDirectory(){ JFileChooser chooser = new MockJFileChooser(); File dir = chooser.getCurrentDirectory(); Assert.assertTrue(dir.exists()); Assert.assertTrue(dir instanceof MockFile); }