Java Code Examples for javax.swing.JFileChooser#setCurrentDirectory()
The following examples show how to use
javax.swing.JFileChooser#setCurrentDirectory() .
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: BasicProjectPanelVisual.java From nb-springboot with Apache License 2.0 | 8 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(null); chooser.setDialogTitle("Select Project Location"); 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 2
Source File: ColorPrefsOpenHandler.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Action performed. * * @param event the event * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */ @Override public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Load color preferences file"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (this.main.getColorSettingsDir() != null) { fileChooser.setCurrentDirectory(this.main.getColorSettingsDir()); } int rc = fileChooser.showOpenDialog(this.main); if (rc == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (file.exists() && file.isFile()) { this.main.setColorSettingsDir(file.getParentFile()); this.main.setColorSettingFile(file); try { this.main.loadColorPreferences(this.main.getColorSettingFile()); } catch (IOException e) { this.main.handleException(e); } } } }
Example 3
Source File: FrmMeteoData.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
private void onMM5IMDataClick(ActionEvent e) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String path = this.getStartupPath(); File pathDir = new File(path); JFileChooser aDlg = new JFileChooser(); aDlg.setCurrentDirectory(pathDir); if (JFileChooser.APPROVE_OPTION == aDlg.showOpenDialog(this)) { File file = aDlg.getSelectedFile(); //this._parent.setCurrentDataFolder(file.getParent()); System.setProperty("user.dir", file.getParent()); MeteoDataInfo aDataInfo = new MeteoDataInfo(); aDataInfo.openMM5IMData(file.getAbsolutePath()); addMeteoData(aDataInfo); } this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
Example 4
Source File: FrmJoinNCFiles.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
private void jButton_DataFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_DataFolderActionPerformed // TODO add your handling code here: JFileChooser aDlg = new JFileChooser(); String path = System.getProperty("user.dir"); File pathDir = new File(path); if (pathDir.isDirectory()) { aDlg.setCurrentDirectory(pathDir); } aDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (JFileChooser.APPROVE_OPTION == aDlg.showOpenDialog(this)) { File aFile = aDlg.getSelectedFile(); System.setProperty("user.dir", aFile.getAbsolutePath()); this.setDataFolder(aFile); } }
Example 5
Source File: LandUseBalloonPanel.java From importer-exporter with Apache License 2.0 | 6 votes |
private void loadFile() { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html"); fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(filter); if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) { fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath())); } else { fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath())); } int result = fileChooser.showSaveDialog(getTopLevelAncestor()); if (result == JFileChooser.CANCEL_OPTION) return; try { String exportString = fileChooser.getSelectedFile().toString(); browseText.setText(exportString); internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath()); internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED); } catch (Exception e) { // } }
Example 6
Source File: ScrMainMenu.java From PolyGlot with MIT License | 6 votes |
/** * opens Language file */ public void open() { String curFileName = core.getCurFileName(); JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Open Language File"); FileNameExtensionFilter filter = new FileNameExtensionFilter("PolyGlot Languages", "pgd"); chooser.setFileFilter(filter); String fileName; if (curFileName.isEmpty()) { chooser.setCurrentDirectory(core.getWorkingDirectory()); } else { chooser.setCurrentDirectory(IOHandler.getDirectoryFromPath(curFileName)); } if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { // only open if save/cancel test is passed if (!saveOrCancelTest()) { return; } fileName = chooser.getSelectedFile().getAbsolutePath(); openFileFromPath(fileName); } genTitle(); }
Example 7
Source File: VegetationBalloonPanel.java From importer-exporter with Apache License 2.0 | 6 votes |
private void loadFile() { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html"); fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(filter); if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) { fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath())); } else { fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath())); } int result = fileChooser.showSaveDialog(getTopLevelAncestor()); if (result == JFileChooser.CANCEL_OPTION) return; try { String exportString = fileChooser.getSelectedFile().toString(); browseText.setText(exportString); internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath()); internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED); } catch (Exception e) { // } }
Example 8
Source File: ChartPanel.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs); FileNameExtensionFilter filter = new FileNameExtensionFilter( localizationResources.getString("PNG_Image_Files"), "png"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
Example 9
Source File: SnapshotCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
public void actionPerformed(ActionEvent e) { if (e.getSource() == saveToFileButton) { JFileChooser fileChooser = getFileChooser(); fileChooser.setCurrentDirectory(new File(saveToFileField.getText()).getParentFile()); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { saveToFileField.setText(fileChooser.getSelectedFile().getAbsolutePath()); } } }
Example 10
Source File: MainINSECTForm.java From Ngram-Graphs with Apache License 2.0 | 5 votes |
private void AnalyzeFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnalyzeFileBtnActionPerformed // Select a file JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); int iRes = fc.showOpenDialog(this); if (iRes != JFileChooser.APPROVE_OPTION) return; checkFile(fc.getSelectedFile().getAbsolutePath(), NEW_CATEGORY, true); }
Example 11
Source File: FPortecle.java From portecle with GNU General Public License v2.0 | 5 votes |
/** * Open a keystore file from disk. * * @return True if a keystore is opened, false otherwise */ private boolean openKeyStoreFile() { // Does the current keystore contain unsaved changes? if (needSave()) { // Yes - ask the user if it should be saved int iWantSave = wantSave(); if ((iWantSave == JOptionPane.YES_OPTION && !saveKeyStore()) || iWantSave == JOptionPane.CANCEL_OPTION) { return false; } } // Let the user choose a file to open from JFileChooser chooser = FileChooserFactory.getKeyStoreFileChooser(null); File fLastDir = m_lastDir.getLastDir(); if (fLastDir != null) { chooser.setCurrentDirectory(fLastDir); } chooser.setDialogTitle(RB.getString("FPortecle.OpenKeyStoreFile.Title")); chooser.setMultiSelectionEnabled(false); int iRtnValue = chooser.showOpenDialog(this); if (iRtnValue == JFileChooser.APPROVE_OPTION) { File fOpenFile = chooser.getSelectedFile(); // File chosen - open the keystore if (openKeyStoreFile(fOpenFile, true)) { return true; } } return false; }
Example 12
Source File: GuiUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static File[] showOpenFolderDialog( final Component parent, final String title, final boolean multiselection, final File initialPath ) { RunnableWithParameters runnable = new RunnableWithParameters(){ public void run() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(title); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setMultiSelectionEnabled(multiselection); fc.setCurrentDirectory(initialPath); fc.setFileHidingEnabled(false); int r = fc.showOpenDialog(parent); if (r != JFileChooser.APPROVE_OPTION) { this.returnValue = null; return; } if (fc.isMultiSelectionEnabled()) { File[] selectedFiles = fc.getSelectedFiles(); this.returnValue = selectedFiles; } else { File selectedFile = fc.getSelectedFile(); if (selectedFile != null && selectedFile.exists()) PreferencesHandler.setLastPath(selectedFile.getAbsolutePath()); this.returnValue = new File[]{selectedFile}; } } }; if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (Exception e) { Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e); } } return (File[]) runnable.getReturnValue(); }
Example 13
Source File: InstallPear.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Opens a dialog to select a directory for PEAR file installation. * * @return Selected installation directory path, or current directory path, if nothing was * selected. */ private String selectDir() { userPrefs = Preferences.userNodeForPackage(this.getClass()); JFileChooser fileChooser = new JFileChooser(); fileChooser.addChoosableFileFilter(new PEARFilter()); String lastDirName = (installDirTextField.getText().length() > 0) ? installDirTextField .getText() : userPrefs.get(LAST_DIRECTORY_CHOOSEN_KEY, "./"); String selectedDirName = null; File directory = (lastDirName.length() > 0) ? new File(lastDirName).getParentFile() : new File( "./"); fileChooser.setCurrentDirectory(directory); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fileChooser.showDialog(new JFrame(), "Select"); // User selects the 'Select Button' if (result == JFileChooser.APPROVE_OPTION) { selectedDirName = fileChooser.getSelectedFile().getAbsolutePath(); // saving the state of the window try { userPrefs.put(LAST_DIRECTORY_CHOOSEN_KEY, selectedDirName); } catch (NullPointerException ex) { pearConsole.append("NullPointerException" + ex); } installDirTextField.setText(selectedDirName); installButton.setEnabled(true); } // no selection was made else { installButton.setEnabled(true); } return selectedDirName; }
Example 14
Source File: XmiCasFileOpenHandler.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open XMI CAS file"); if (this.main.getXcasFileOpenDir() != null) { fileChooser.setCurrentDirectory(this.main.getXcasFileOpenDir()); } int rc = fileChooser.showOpenDialog(this.main); if (rc == JFileChooser.APPROVE_OPTION) { File xmiCasFile = fileChooser.getSelectedFile(); if (xmiCasFile.exists() && xmiCasFile.isFile()) { this.main.loadXmiFile(xmiCasFile); } } }
Example 15
Source File: AutoSummENGGui.java From Ngram-Graphs with Apache License 2.0 | 5 votes |
/** Select the directory of the peer summaries. */ private void BrowseSummaryDirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseSummaryDirBtnActionPerformed // Select a dir JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory((SummariesRootDirEdt.getText().length() == 0) ? new java.io.File(".") : new java.io.File(SummariesRootDirEdt.getText())); fc.setSelectedFile(fc.getCurrentDirectory()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int iRet = fc.showOpenDialog(this); if (iRet == JFileChooser.APPROVE_OPTION) { SummariesRootDirEdt.setText(fc.getSelectedFile().getAbsolutePath()); } }
Example 16
Source File: DemoUtils.java From java-ocr-api with GNU Affero General Public License v3.0 | 5 votes |
public static JFileChooser registerBrowseButtonListener(final JComboBox comboBox, final JButton button, final boolean chooseFile, final boolean isOpen, final FileFilter fileFilter, final File initialDirectory) { if(! comboBox.isEditable()) { throw new IllegalArgumentException("The combo box must be editable."); } final JFileChooser fileChooser = new JFileChooser(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { fileChooser.setCurrentDirectory(comboBox.getSelectedItem() == null || comboBox.getSelectedItem().toString().trim().length() == 0 ? initialDirectory : new File(comboBox.getSelectedItem().toString())); fileChooser.setFileSelectionMode(chooseFile ? JFileChooser.FILES_ONLY : JFileChooser.DIRECTORIES_ONLY); if(fileFilter != null) { fileChooser.addChoosableFileFilter(fileFilter); } int ret = isOpen ? fileChooser.showOpenDialog(comboBox) : fileChooser.showSaveDialog(comboBox); if(ret == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); comboBox.getEditor().setItem(file.getAbsolutePath()); } } }; button.addActionListener(listener); return fileChooser; }
Example 17
Source File: FolderChooserDialog.java From pgptool with GNU General Public License v3.0 | 5 votes |
protected void onPostConstruct(JFileChooser ofd) { if (optionalRecentlyUsedFolder != null) { String startFolder = optionalRecentlyUsedFolder.getValue(); if (startFolder != null) { ofd.setCurrentDirectory(new File(startFolder)); ofd.setSelectedFile(new File(startFolder)); } } }
Example 18
Source File: ExistingFileChooserDialog.java From pgptool with GNU General Public License v3.0 | 5 votes |
protected void suggestInitialDirectory(JFileChooser ofd) { try { String lastChosenDestination = configPairs.find(configPairNameToRemember, null); String pathname = StringUtils.hasText(lastChosenDestination) ? lastChosenDestination : SystemUtils.getUserHome().getAbsolutePath(); ofd.setCurrentDirectory(new File(pathname)); } catch (Throwable t) { log.warn("Failed to set suggested location by key " + configPairNameToRemember, t); } }
Example 19
Source File: EditPanel.java From KEEL with GNU General Public License v3.0 | 4 votes |
private void savejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savejButtonActionPerformed if (this.editDataPanel.getData().getAttributes().size() == 0) { JOptionPane.showMessageDialog(this, "Please, insert at least one variable", "Error", 2); return; } JFileChooser chooser = new JFileChooser(); KeelFileFilter fileFilter = new KeelFileFilter(); fileFilter.addExtension("dat"); fileFilter.setFilterName("KEEL Files (.dat)"); chooser.setFileFilter(fileFilter); chooser.setCurrentDirectory(Path.getFilePath()); if(!this.loadjTextField.getText().equals("")) chooser.setSelectedFile(new File(this.loadjTextField.getText())); int opcion = chooser.showSaveDialog(this); Path.setFilePath(chooser.getCurrentDirectory()); String cadena, aux; boolean ok; if (opcion == JFileChooser.APPROVE_OPTION && this.editDataPanel.getStateAddButton()) { String nombre = chooser.getSelectedFile().getAbsolutePath(); if (!nombre.toLowerCase().endsWith(".dat") && !nombre.toLowerCase().endsWith(".txt")) { // Add correct extension nombre += ".dat"; } File tmp = new File(nombre); if (!tmp.exists() || JOptionPane.showConfirmDialog(this, "File " + nombre + " already exists. Do you want to replace it?", "Confirm", JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) { imprimeCabecera(nombre); for (int i = 0; i < this.editDataPanel.getTablaDataset().getData().length; i++) { cadena = ""; ok = false; for (int j = 0; j < this.editDataPanel.getData().getNVariables(); j++) { if (!ok) { if (this.editDataPanel.getTablaDataset().getData()[i][j] == null || (this.editDataPanel.getTablaDataset().getData().toString()).equalsIgnoreCase( "<null>")) { cadena += "<null>"; } else { cadena += this.editDataPanel.getTablaDataset().getData()[i][j]; } ok = true; } else { if (this.editDataPanel.getTablaDataset().getData() == null || (this.editDataPanel.getTablaDataset().getData().toString()).equalsIgnoreCase( "<null>")) { cadena += ", <null>"; } else { cadena += ", " + this.editDataPanel.getTablaDataset().getData()[i][j]; } } } cadena += "\n"; Files.addToFile(nombre, cadena); } JOptionPane.showMessageDialog(this, "DataSet created", "Info", JOptionPane.INFORMATION_MESSAGE); // Perform partitions? if(showPartition){ Object[] options = {"Yes", "No"}; int n = JOptionPane.showOptionDialog(parent, "Do you want to make partitions for this dataset?", "Make partitions", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (n == 0) { if (dataCFFrame != null) { dataCFFrame.addPartitionTab(tmp); } } showPartition = false; } } } }
Example 20
Source File: ResultsManager.java From visualvm with GNU General Public License v2.0 | 4 votes |
SelectedFile selectSnapshotTargetFile(final String defaultName, final boolean heapdump) { String targetName; FileObject targetDir; // 1. let the user choose file or directory JFileChooser chooser = new JFileChooser(); if (exportDir != null) { chooser.setCurrentDirectory(exportDir); } chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(Bundle.ResultsManager_SelectFileOrDirDialogCaption()); chooser.setApproveButtonText(Bundle.ResultsManager_SaveButtonName()); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith("." + (heapdump ? HEAPDUMP_EXTENSION : SNAPSHOT_EXTENSION)); //NOI18N } public String getDescription() { if (heapdump) { return Bundle.ResultsManager_ProfilerHeapdumpFileFilter(HEAPDUMP_EXTENSION); } return Bundle.ResultsManager_ProfilerSnapshotFileFilter(SNAPSHOT_EXTENSION); } }); if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) { return null; // cancelled by the user } // 2. process both cases and extract file name and extension to use File file = chooser.getSelectedFile(); String targetExt = heapdump ? HEAPDUMP_EXTENSION : SNAPSHOT_EXTENSION; if (file.isDirectory()) { // save to selected directory under default name exportDir = chooser.getCurrentDirectory(); targetDir = FileUtil.toFileObject(FileUtil.normalizeFile(file)); targetName = defaultName; } else { // save to selected file exportDir = chooser.getCurrentDirectory(); targetDir = FileUtil.toFileObject(FileUtil.normalizeFile(exportDir)); String fName = file.getName(); // divide the file name into name and extension int idx = fName.lastIndexOf('.'); // NOI18N if (idx == -1) { // no extension targetName = fName; // extension will be used from source file } else { // extension exists if (heapdump || fName.endsWith("." + targetExt)) { // NOI18N targetName = fName.substring(0, idx); targetExt = fName.substring(idx + 1); } else { targetName = fName; } } } // 3. return a newly created FileObject return new SelectedFile(targetDir, targetName, targetExt); }