Java Code Examples for javax.swing.JFileChooser#showOpenDialog()
The following examples show how to use
javax.swing.JFileChooser#showOpenDialog() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageChooser.java From nextreports-designer with Apache License 2.0 | 6 votes |
public static String showDialog(Component parent, String title, String initialImage) { JFileChooser fc = new JFileChooser(); ImagePreviewPanel previewPane = new ImagePreviewPanel(); fc.setAccessory(previewPane); fc.addPropertyChangeListener(previewPane); fc.setDialogTitle(I18NSupport.getString("image.title")); fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new ImageFilter()); int returnVal = fc.showOpenDialog(Globals.getMainFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = fc.getSelectedFile(); if (f != null) { try { FileUtil.copyToDir(f, new File(Globals.getCurrentReportAbsolutePath()).getParentFile(), true); } catch (IOException e) { e.printStackTrace(); } return f.getName(); } } return null; }
Example 2
Source File: BasicProjectInfoPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void browseAntScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseAntScriptActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); if (antScript.getText().length() > 0 && getAntScript().exists()) { chooser.setSelectedFile(getAntScript()); } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) { chooser.setSelectedFile(getProjectLocation()); } else { chooser.setSelectedFile(ProjectChooser.getProjectsFolder()); } chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Build_Script")); //NOI18N if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File script = FileUtil.normalizeFile(chooser.getSelectedFile()); antScript.setText(script.getAbsolutePath()); } }
Example 3
Source File: ScrPrintToPDF.java From PolyGlot with MIT License | 6 votes |
private void btnSelectSavePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectSavePathActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Save Language"); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf"); String fileName = core.getCurFileName().replaceAll(".pgd", ".pdf"); chooser.setFileFilter(filter); chooser.setApproveButtonText("Save"); chooser.setCurrentDirectory(core.getWorkingDirectory()); chooser.setSelectedFile(new File(fileName)); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath(); if (!fileName.contains(".pdf")) { fileName += ".pdf"; } txtSavePath.setText(fileName); } }
Example 4
Source File: ScenarioEditor.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Load a map and scenario by showing a file chooser dialog. @throws CancelledByUserException If the user cancels the change due to unsaved changes. @throws MapException If there is a problem reading the map. @throws ScenarioException If there is a problem reading the scenario. * @throws rescuecore2.scenario.exceptions.ScenarioException */ public void load() throws CancelledByUserException, MapException, ScenarioException, rescuecore2.scenario.exceptions.ScenarioException { JFileChooser chooser = new JFileChooser(baseDir); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory(); } @Override public String getDescription() { return "Directories"; } }); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { load(chooser.getSelectedFile()); } }
Example 5
Source File: OpenHeapWalkerAction.java From visualvm with GNU General Public License v2.0 | 6 votes |
private static File getHeapDumpFile() { JFileChooser chooser = new JFileChooser(); if (importDir != null) { chooser.setCurrentDirectory(importDir); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.addChoosableFileFilter(new FileFilterImpl()); chooser.setDialogTitle( Bundle.OpenHeapWalkerAction_DialogCaption() ); if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) { importDir = chooser.getCurrentDirectory(); return chooser.getSelectedFile(); } return null; }
Example 6
Source File: NbProcessDescriptorCustomEditor.java From netbeans with Apache License 2.0 | 6 votes |
private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // Add your handling code here: JFileChooser chooser = org.netbeans.beaninfo.editors.FileEditor.createHackedFileChooser(); chooser.setMultiSelectionEnabled (false); File init = new File(processField.getText()); // #13372 if (init.isFile()) { chooser.setCurrentDirectory(init.getParentFile()); chooser.setSelectedFile(init); } int retVal = chooser.showOpenDialog (this); if (retVal == JFileChooser.APPROVE_OPTION) { String absolute_name = chooser.getSelectedFile ().getAbsolutePath (); //System.out.println("file:" + absolute_name); // NOI18N processField.setText (absolute_name); } }
Example 7
Source File: PanelProjectLocationVisual.java From netbeans with Apache License 2.0 | 6 votes |
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { // NOI18N JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(NbBundle.getMessage(PanelSourceFolders.class, "LBL_NWP1_SelectProjectLocation")); // NOI18N chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String path = this.projectLocationTextField.getText(); if (path.length() > 0) { File f = new File(path); if (f.exists()) { chooser.setSelectedFile(f); } } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } panel.fireChangeEvent(); } }
Example 8
Source File: MainFrame.java From procamtracker with GNU General Public License v2.0 | 6 votes |
private void settingsLoadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsLoadMenuItemActionPerformed JFileChooser fc = new JFileChooser(); if (settingsFile != null) { fc.setSelectedFile(settingsFile); } else { fc.setSelectedFile(DEFAULT_SETTINGS_FILE); } int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try { loadSettings(file); } catch (Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Could not load settings from \"" + file + "\"", ex); } } }
Example 9
Source File: SignUI.java From Websocket-Smart-Card-Signer with GNU Affero General Public License v3.0 | 6 votes |
public static List<Data> showFileSelection() throws Exception{ List<Data> ret = new ArrayList<Data>(); JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); jfc.setDialogTitle("Choose the files to sign"); SignUtils.playBeeps(1); if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) return null; File[] choosedFileList = jfc.getSelectedFiles(); for(File file:choosedFileList){ String id = file.getAbsolutePath(); byte[] fileContent = IOUtils.readFile(file); ret.add(new Data(id, fileContent)); } return ret; }
Example 10
Source File: OutputPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void javadocBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javadocBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES); chooser.setMultiSelectionEnabled(false); if (lastChosenFile != null) { chooser.setSelectedFile(lastChosenFile); } else if (javadoc.getText().length() > 0) { chooser.setSelectedFile(new File(javadoc.getText())); } else { File files[] = model.getBaseFolder().listFiles(); if (files != null && files.length > 0) { chooser.setSelectedFile(files[0]); } else { chooser.setSelectedFile(model.getBaseFolder()); } } chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Javadoc")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = chooser.getSelectedFile(); file = FileUtil.normalizeFile(file); javadoc.setText(file.getAbsolutePath()); lastChosenFile = file; } }
Example 11
Source File: ConfigureFXMLControllerPanelVisual.java From netbeans with Apache License 2.0 | 6 votes |
private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseButtonActionPerformed JFileChooser chooser = new JFileChooser(new FXMLTemplateWizardIterator.SrcFileSystemView(support.getSourceGroupsAsFiles())); chooser.setDialogTitle(NbBundle.getMessage(ConfigureFXMLControllerPanelVisual.class, "LBL_ConfigureFXMLPanel_FileChooser_Select_Controller")); // NOI18N chooser.setFileFilter(FXMLTemplateWizardIterator.FXMLTemplateFileFilter.createJavaFilter()); String existingPath = existingNameTextField.getText(); if (existingPath.length() > 0) { File f = new File(support.getCurrentChooserFolder().getPath() + File.pathSeparator + existingPath); if (f.exists()) { chooser.setSelectedFile(f); } else { chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder())); } } else { chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder())); } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { String controllerClass = FileUtil.normalizeFile(chooser.getSelectedFile()).getPath(); // XXX check other roots ? final String srcPath = FileUtil.normalizeFile(FileUtil.toFile(support.getCurrentSourceGroupFolder())).getPath(); final String relativePath = controllerClass.substring(srcPath.length() + 1); final String relativePathWithoutExt = relativePath.substring(0, relativePath.indexOf(FXMLTemplateWizardIterator.JAVA_FILE_EXTENSION)); existingNameTextField.setText(relativePathWithoutExt.replace(File.separatorChar, '.')); // NOI18N } }
Example 12
Source File: NbPlatformCustomizerJavadoc.java From netbeans with Apache License 2.0 | 5 votes |
private void addZipFolder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addZipFolder JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastUsedNbPlatformLocation()); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase(Locale.US).endsWith(".jar") || // NOI18N f.getName().toLowerCase(Locale.US).endsWith(".zip"); // NOI18N } public String getDescription() { return getMessage("CTL_JavadocTab"); } }); int ret = chooser.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File javadocRoot = FileUtil.normalizeFile(chooser.getSelectedFile()); URL newUrl = FileUtil.urlForArchiveOrDir(javadocRoot); if (model.containsRoot(newUrl)) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( getMessage("MSG_ExistingJavadocRoot"))); } else { ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(javadocRoot.getParentFile().getAbsolutePath()); model.addJavadocRoot(newUrl); javadocList.setSelectedValue(newUrl, true); } } // XXX support adding Javadoc URL too (see java.j2seplatform) }
Example 13
Source File: PickIconAction.java From netbeans with Apache License 2.0 | 5 votes |
protected @Override void performAction(Node[] activatedNodes) { FileObject f = PickNameAction.findFile(activatedNodes); if (f == null) { return; } NbModuleProvider p = PickNameAction.findProject(f); if (p == null) { return; } FileObject src = p.getSourceDirectory(); JFileChooser chooser = UIUtil.getIconFileChooser(); chooser.setCurrentDirectory(FileUtil.toFile(src)); if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) { return; } FileObject icon = FileUtil.toFileObject(chooser.getSelectedFile()); // XXX might instead get WritableXMLFileSystem.cp and search for it in there: String iconPath = FileUtil.getRelativePath(src, icon); try { if (iconPath == null) { String folderPath; String layerPath = ManifestManager.getInstance(Util.getManifest(p.getManifestFile()), false).getLayer(); if (layerPath != null) { folderPath = layerPath.substring(0, layerPath.lastIndexOf('/')); } else { folderPath = p.getCodeNameBase().replace('.', '/') + "/resources"; // NOI18N } FileObject folder = FileUtil.createFolder(src, folderPath); FileUtil.copyFile(icon, folder, icon.getName(), icon.getExt()); iconPath = folderPath + '/' + icon.getNameExt(); } f.setAttribute("iconBase", iconPath); // NOI18N } catch (IOException e) { Util.err.notify(ErrorManager.INFORMATIONAL, e); } }
Example 14
Source File: GrammarImportExport.java From Forsythia with GNU General Public License v3.0 | 5 votes |
private File getGrammarFile(){ JFileChooser fc=new JFileChooser(); fc.setCurrentDirectory(getImportExportDir()); int r=fc.showOpenDialog(GE.ge.getUIMain()); if(r!=JFileChooser.APPROVE_OPTION) return null; File selectedfile=fc.getSelectedFile(); importexportdir=fc.getCurrentDirectory(); return selectedfile;}
Example 15
Source File: DebugMenu.java From whyline with MIT License | 5 votes |
private void generateUsageStatistics() throws IOException { String methodname = JOptionPane.showInputDialog(whylineUI, "Which method is the bug in (e.g., \"java/lang/Character.isDefined(C)Z\")?"); if(methodname == null) return; String[] names = methodname.split("\\."); if(names.length != 2) { JOptionPane.showMessageDialog(whylineUI, "Couldn't split into class and method name"); return; } Classfile buggyClass = whylineUI.getTrace().getClassfileByName(QualifiedClassName.get(names[0])); if(buggyClass == null) { JOptionPane.showMessageDialog(whylineUI, "Couldn't find class " + names[0]); return; } MethodInfo buggyMethod = buggyClass.getDeclaredMethodByNameAndDescriptor(names[1]); if(buggyMethod == null) { JOptionPane.showMessageDialog(whylineUI, "Couldn't find method " + names[1] + " in " + names[0]); return; } JFileChooser chooser = new JFileChooser(whylineUI.getTrace().getPath()); chooser.setDialogTitle("Select a folder that contains the usage logs to analyze"); chooser.setFileHidingEnabled(true); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int choice = chooser.showOpenDialog(whylineUI); if(choice != JFileChooser.APPROVE_OPTION) return; File folder = chooser.getSelectedFile(); Usage usage = new Usage(whylineUI.getTrace(), folder, buggyMethod); JOptionPane.showMessageDialog(whylineUI, "Saved 'results.csv' in " + folder.getName()); }
Example 16
Source File: PsychoPanel2.java From psychoPATH with GNU General Public License v3.0 | 5 votes |
private void webrootLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_webrootLoadButtonActionPerformed JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(PsychoPanel2.this); if (returnVal == JFileChooser.APPROVE_OPTION) { Scanner inFile1; try { inFile1 = new Scanner(fc.getSelectedFile()).useDelimiter("\\r*\\n"); } catch (FileNotFoundException ex) { Logger.getLogger(PsychoPanel2.class.getName()).log(Level.SEVERE, null, ex); return; } List<String> temps = new ArrayList<>(); while (inFile1.hasNext()) { String line = inFile1.next(); temps.add(line); } inFile1.close(); //suffixesList.setListData((String[])temps.toArray()); // for some reason casting (String[]) on toArray() does not work as expected (empty data list) //String[] empty={}; //docrootsList.setListData(empty); String[] newArr = new String[temps.size()]; for(int i=0;i<temps.size();i++) { newArr[i]=temps.get(i); } docrootsList.setListData(newArr); //appendListData(docrootsList,newArr); } }
Example 17
Source File: MainViewerGUI.java From bytecode-viewer with GNU General Public License v3.0 | 5 votes |
public void library() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory(); } @Override public String getDescription() { return "Optional Library Folder"; } }); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileHidingEnabled(false); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) try { BytecodeViewer.library = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } }
Example 18
Source File: MainForm.java From zxpoly with GNU General Public License v3.0 | 5 votes |
private void menuFileLoadPokeActionPerformed(ActionEvent evt) { stepSemaphor.lock(); try { this.turnZxKeyboardOff(); final JFileChooser trainerFileChooser = new JFileChooser(this.lastPokeFileFolder); trainerFileChooser.setDialogTitle("Select trainer"); trainerFileChooser.setMultiSelectionEnabled(false); trainerFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); trainerFileChooser.setAcceptAllFileFilterUsed(false); final FileFilter pokTrainer = new TrainerPok(); trainerFileChooser.addChoosableFileFilter(pokTrainer); if (trainerFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final AbstractTrainer selectedTrainer = (AbstractTrainer) trainerFileChooser.getFileFilter(); final File selectedFile = trainerFileChooser.getSelectedFile(); this.lastPokeFileFolder = selectedFile.getParentFile(); try { selectedTrainer.apply(this, selectedFile, this.board); } catch (Exception ex) { LOGGER.log(Level.WARNING, "Error during trainer processing: " + ex.getMessage(), ex); JOptionPane.showMessageDialog(this, ex.getMessage(), "Can't read or parse file", JOptionPane.ERROR_MESSAGE); } } } finally { this.turnZxKeyboardOn(); stepSemaphor.unlock(); } }
Example 19
Source File: MetalworksFrame.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void openDocument() { JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(this); }
Example 20
Source File: Main.java From scava with Eclipse Public License 2.0 | 4 votes |
public static void main(String[] args) { Vector<Target> targets = new Vector<Target>(); Target m2mTarget = new Target(); m2mTarget.setName(M2M); Target m2tTarget = new Target(); m2tTarget.setName(M2T); Target setupTarget = new Target(); setupTarget.setName(SETUP); File buildFile = new File(BUILD_XML); Project p = new Project(); p.setUserProperty(ANT_FILE, buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference(ANT_PROJECT_HELPER, helper); helper.parse(p, buildFile); Scanner scanner = new Scanner(System.in); while (true){ System.out.println("Which transformation would you like to start? (M2M / M2T) : "); String target = scanner.next(); if (target.equals(M2M)){ System.out.println("Select the OpenAPI JSON schema to transform."); try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setCurrentDirectory(new File(SCHEMAS_DIR)); chooser.showOpenDialog(null); File selectedFile = chooser.getSelectedFile(); if (selectedFile.isFile() && selectedFile.getName().endsWith(".json")){ System.out.println(selectedFile.getName()); targets.add(m2mTarget); break; } else { chooser = null; System.out.println("Something went wrong"); } //p.executeSortedTargets(targets); } else if (target.equals(M2M)){ //p.executeTarget(p.getDefaultTarget()); break; } else { System.out.println("Invalid"); } } scanner.close(); }