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; }
private void retrieveSaveDialogDir(JFileChooser fc) { try { String currentDirStr = luytenPrefs.getFileSaveCurrentDirectory(); if (currentDirStr != null && currentDirStr.trim().length() > 0) { File currentDir = new File(currentDirStr); if (currentDir.exists() && currentDir.isDirectory()) { fc.setCurrentDirectory(currentDir); } } } catch (Exception e) { Luyten.showExceptionDialog("Exception!", e); } }
static public void getFilename(String title, int type) { int returnVal; fileChooser.setDialogTitle(title); fileChooser.setCurrentDirectory(file); fileChooser.setDialogType(type); if (type == JFileChooser.OPEN_DIALOG) { returnVal = fileChooser.showOpenDialog(jframe); } else { returnVal = fileChooser.showSaveDialog(jframe); } if (returnVal == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); filename = file.getAbsolutePath(); prefs.put(FILENAME_PREFERENCE, filename); } }
public static void main(String[] args){ JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("D:\\outlook")); chooser.showSaveDialog(null); }
@Override public void actionPerformed(final ActionEvent e) { final GCDocument gcDocument = gcViewer.getSelectedGCDocument(); for (int i=0; i<gcDocument.getChartPanelViewCount(); i++) { final ChartPanelView chartPanelView = gcDocument.getChartPanelView(i); final File file = new File(chartPanelView.getGCResource().getResourceName()); saveDialog.setCurrentDirectory(file.getParentFile()); saveDialog.setSelectedFile(file); final int val = saveDialog.showSaveDialog(gcViewer); if (val == JFileChooser.APPROVE_OPTION) { ExportExtensionFileFilter fileFilter = (ExportExtensionFileFilter) saveDialog.getFileFilter(); // On OS/X if you don't select one of the filters and just press "Save" the filter may be null. Use the CSV one then if (fileFilter==null) { fileFilter = (ExportExtensionFileFilter) saveDialog.getChoosableFileFilters()[0]; } exportFile(chartPanelView.getGCResource().getModel(), saveDialog.getSelectedFile(), fileFilter.getExtension(), fileFilter.getDataWriterType()); } else if (val == JFileChooser.ERROR_OPTION) { JOptionPane.showMessageDialog(gcViewer, LocalisationHelper.getString("fileexport_dialog_error_occured"), LocalisationHelper.getString("fileexport_dialog_write_file_failed"), JOptionPane.ERROR_MESSAGE); } } }
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
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; if(pref.get("LAST_PATH", "") != null){ // set last SELECTED file/directory path. chooser = new JFileChooser(pref.get("LAST_PATH", "")); } else{ // set currentDirectory, but dont select anything yet. chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(home_dir)); }
protected void playerLoadDeck() { String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", ""); if (!lastFolder.isEmpty()) { fcSelectDeck.setCurrentDirectory(new File(lastFolder)); } int ret = fcSelectDeck.showDialog(this, "Select Deck"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fcSelectDeck.getSelectedFile(); this.txtPlayerDeck.setText(file.getPath()); try { MageFrame.getPreferences().put("lastDeckFolder", file.getCanonicalPath()); } catch (IOException ex) { } } fcSelectDeck.setSelectedFile(null); }
private void retrieveOpenDialogDir(JFileChooser fc) { try { String currentDirStr = luytenPrefs.getFileOpenCurrentDirectory(); if (currentDirStr != null && currentDirStr.trim().length() > 0) { File currentDir = new File(currentDirStr); if (currentDir.exists() && currentDir.isDirectory()) { fc.setCurrentDirectory(currentDir); } } } catch (Exception e) { Luyten.showExceptionDialog("Exception!", e); } }
public static File chooseDirOpen(File dir, String title) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(dir); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.showSaveDialog(null); File saveTo = chooser.getSelectedFile(); return saveTo; }
private void browseWSDLFile(){ fileChooser.setFileFilter(new WSDLFileFilter()); fileChooser.setCurrentDirectory(archiveBean.getClassLoc()); int returnVal = fileChooser.showOpenDialog(btnBrowse); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); txtWSDL.setText(file.getAbsolutePath()); } } }
private void displayDialogChangeDir() { final JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); chooser.setDialogTitle("Directory to watch:"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); final String currentPath = prefs.get(KEY_DIR, "."); chooser.setCurrentDirectory(new File(currentPath)); Log.info("Showing OpenDialog"); final int returnVal = chooser.showOpenDialog(this); Log.info("Closing OpenDialog"); if (returnVal == JFileChooser.APPROVE_OPTION) { final File dir = chooser.getSelectedFile(); changeDir(dir); } }
JFileChooser chooser = new JFileChooser(); try { // Create a File object containing the canonical path of the // desired directory File f = new File(new File(".").getCanonicalPath()); // Set the current directory chooser.setCurrentDirectory(f); } catch (IOException e) { }
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", ""); if (!lastFolder.isEmpty()) { fcSelectDeck.setCurrentDirectory(new File(lastFolder)); File file = fcSelectDeck.getSelectedFile(); file = new File(lastFolder);
public static File chooseFileSave(File dir, String title) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(dir); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.showSaveDialog(null); File saveTo = chooser.getSelectedFile(); return saveTo; }
private File promptForRepositoryBaseDir() { final JFileChooser fileChooser = createDirectoryChooser(); fileChooser.setCurrentDirectory(currentDirectory); final int response = fileChooser.showOpenDialog(mainPanel); currentDirectory = fileChooser.getCurrentDirectory(); final File selectedDir = fileChooser.getSelectedFile(); if (response == JFileChooser.APPROVE_OPTION) { return selectedDir; } return null; }
public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select a Java installation directory..."); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); Preferences p = Preferences.userNodeForPackage(Installer.class); final String prefID = "defaultDirectory"; fc.setCurrentDirectory(new File(p.get(prefID, "."))); if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { Path dir = fc.getSelectedFile().toPath(); p.put(prefID, dir.getParent().toString()); try { installations.add(new Installation(config, dir)); } catch (IOException ex) { MainWindow.showInstallerException(ex, parent); } } } }
private JFileChooser makeJFileChooser() { final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(java.util.ResourceBundle.getBundle("jpcsp/languages/jpcsp").getString("MainGUI.strOpenELFPBP.text")); fc.setCurrentDirectory(new java.io.File(".")); return fc; } private void OpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenFileActionPerformed
public static File chooseFile(File dir, String title, int selectionMode) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(dir); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.showSaveDialog(null); File saveTo = chooser.getSelectedFile(); return saveTo; }