private void browseFiles() { jfc.setDialogTitle("Open file"); int status = jfc.showOpenDialog(this); if (status == JFileChooser.APPROVE_OPTION) { urlTextField.setText(jfc.getSelectedFile().getPath()); openButton.setEnabled(true); } }
private File showOpenDir(String title, File lastFile){ final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle(title); if(lastFile != null) fc.setSelectedFile(lastFile); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) return true; return false; } @Override public String getDescription() { return "Directory"; } }); int returnVal = fc.showOpenDialog(null); File file = null; if(returnVal == JFileChooser.APPROVE_OPTION) file = fc.getSelectedFile(); return file; }
/** * Opens a dialog and saves the output of the parser on the current * text. If there is no current text, yell at the user and make * them feel bad instead. */ public void saveOutput() { if (textPane.getText().trim().length() == 0) { JOptionPane.showMessageDialog(this, "No text to parse ", null, JOptionPane.ERROR_MESSAGE); return; } jfc.setDialogTitle("Save file"); int status = jfc.showSaveDialog(this); if (status == JFileChooser.APPROVE_OPTION) { saveOutput(jfc.getSelectedFile().getPath()); } }
File chooseFile(Component parentComponent, String defaultName, String title) { final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(title); fc.setSelectedFile(new File(defaultName)); int returnVal = fc.showSaveDialog(parentComponent); if (returnVal == JFileChooser.APPROVE_OPTION) { return fc.getSelectedFile(); } else { return null; } } }
final JFileChooser importFileDialog = new JFileChooser(PreferencesUtil.getPathFile()); importFileDialog.setDialogTitle(I18n.valueByKey("LIST_IMPORT_CONFIRM_TITLE")); importFileDialog.setMultiSelectionEnabled(true); choice = importFileDialog.showOpenDialog(this.dndList.getTopLevelAncestor()); } catch (ClassCastException | NullPointerException e) { LOGGER.error(e, e);
JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); chooser.setDialogTitle("Add new file"); int returnVal = chooser.showOpenDialog(parent);
JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("select folder"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false);
public Export(final GCViewerGui gcViewer) { this.gcViewer = gcViewer; putValue(NAME, LocalisationHelper.getString("main_frame_menuitem_export")); putValue(MNEMONIC_KEY, new Integer(LocalisationHelper.getString("main_frame_menuitem_mnemonic_export").charAt(0))); putValue(SHORT_DESCRIPTION, LocalisationHelper.getString("main_frame_menuitem_hint_export")); putValue(ACTION_COMMAND_KEY, ActionCommands.EXPORT.toString()); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() )); putValue(SMALL_ICON, ImageHelper.loadImageIcon("save.png")); setEnabled(false); saveDialog = new JFileChooser(); saveDialog.setDialogTitle(LocalisationHelper.getString("fileexport_dialog_title")); saveDialog.removeChoosableFileFilter(saveDialog.getAcceptAllFileFilter()); for (ExportExtensionFileFilter filter : ExportExtensionFileFilter.EXT_FILE_FILTERS) { saveDialog.addChoosableFileFilter(filter); } }
private void prepareFileChooser(JFileChooser chooser) { chooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY : filesOnly ? JFileChooser.FILES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); chooser.setAcceptAllFileFilterUsed(useAcceptAllFileFilter); if (title != null) { chooser.setDialogTitle(title);
private File showOpenFile(String title, File lastFile){ final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(title); if(lastFile != null) fc.setSelectedFile(lastFile); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) return true; String extension = Utils.getExtension(f); if (extension != null) { if (extension.equals("svg")) return true; else return false; } return false; } @Override public String getDescription() { return "SVG images"; } }); int returnVal = fc.showOpenDialog(null); File file = null; if(returnVal == JFileChooser.APPROVE_OPTION) file = fc.getSelectedFile(); return file; }
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); } }
JFrame parentFrame = new JFrame(); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); }
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { // Add a directory final JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select Image Directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) importFromDirectories(chooser.getSelectedFiles()); }
private static JFileChooser getSnapshotDirectoryChooser() { if (snapshotDirectoryChooser == null) { snapshotDirectoryChooser = new JFileChooser(); snapshotDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); snapshotDirectoryChooser.setMultiSelectionEnabled(false); snapshotDirectoryChooser.setDialogType(JFileChooser.OPEN_DIALOG); snapshotDirectoryChooser.setDialogTitle(Bundle.HeapDumpAction_DirectoryDialogCaption()); } return snapshotDirectoryChooser; }
private void initFileChoosers() { if (pngFileChooser == null) { pngFileChooser = new JFileChooser(); pngFileChooser.addChoosableFileFilter(SwingUtil.PNG_FILE_FILTER); pngFileChooser.setDialogTitle("Save PNG"); pngFileChooser.setSelectedFile(new File("geoms.png")); } }
importFileDialog.setDialogTitle(I18n.valueByKey("LIST_EXPORT_TITLE")); int choice = importFileDialog.showSaveDialog(this.myList.getTopLevelAncestor()); if (choice != JFileChooser.APPROVE_OPTION) { FileOutputStream file = new FileOutputStream(importFileDialog.getSelectedFile()) ) { PrintStream out = new PrintStream(file);
/** * Creates a {@code JFileChooser} component and sets it to be for directories only. * * @param parent the component from where the chooser will be launched <i>(should be the main panel of the application)</i>. */ public DirChooser(Component parent) { this.parent = parent; dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setDialogTitle(String.format(I18n.INSTANCE.get("dirchooser.title"), Configuration.INSTANCE.get("application.name"))); dirChooser.setApproveButtonText(I18n.INSTANCE.get("dirchooser.approve.btn")); }
File getDirectory () { if (System.getProperty("os.name").contains("Mac")) { System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog dialog = new FileDialog(GdxSetupUI.this, "Choose destination", FileDialog.LOAD); dialog.setVisible(true); String name = dialog.getFile(); String dir = dialog.getDirectory(); if (name == null || dir == null) return null; return new File(dialog.getDirectory(), dialog.getFile()); } else { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose destination"); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File dir = chooser.getSelectedFile(); if (dir == null) return null; if (dir.getAbsolutePath().trim().length() == 0) return null; return dir; } else { return null; } } }
/** * Opens dialog to load a serialized parser */ public void loadParser() { jfc.setDialogTitle("Load parser"); int status = jfc.showOpenDialog(this); if (status == JFileChooser.APPROVE_OPTION) { String filename = jfc.getSelectedFile().getPath(); if (filename.endsWith(".jar")) { String model = chooseJarParser.show(filename, jfcLocation.location); if (model != null) { loadJarParser(filename, model); } } else { loadParser(filename); } } }
JFrame parentFrame = new JFrame(); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); }