List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
From source file:com.nwn.NwnUpdaterHomeView.java
/** * Allow user to specify their NWN directory * @param evt //from w w w . j av a2 s.c o m */ private void btnSelectNwnDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectNwnDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle("NWN Updater"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showOpenDialog(txtNwnDir); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); txtNwnDir.setText(file.getAbsolutePath()); } }
From source file:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java
/** * 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. *//*from w w w .j a v a2s . c o m*/ @Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs()); 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"; } } ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(), getChartRenderingInfo()); } }
From source file:org.pgptool.gui.ui.tools.browsefs.SaveFileChooserDialog.java
protected void suggestTarget(JFileChooser ofd) { if (configPairs == null || configId == null) { return;/* w w w. ja v a 2s .c o m*/ } try { String lastChosenDestination = configPairs.find(configId, 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 for dialog " + dialogTitleCode, t); } }
From source file:GUI.MyCustomFilter.java
private void NewFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewFileActionPerformed 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) { String path = chooser.getSelectedFile().getAbsolutePath(); String ext = FilenameUtils.getExtension(path); outputPath = path;/* w ww . j a v a 2s . c o m*/ projectSelected = 1; //System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); //System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); } else { System.out.println("No Selection "); } }
From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }/* w w w.ja v a 2s. com*/ } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:com.stanley.captioner.MainFrame.java
private void outputDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_outputDirectoryButtonActionPerformed {//GEN-HEADEREND:event_outputDirectoryButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (lastOutputDirectory != null) { fileChooser.setCurrentDirectory(lastOutputDirectory); }/*from ww w .j ava 2s .c om*/ int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastOutputDirectory = fileChooser.getCurrentDirectory(); File file = fileChooser.getSelectedFile(); outputDirectoryField.setText(file.getAbsolutePath()); if (videoTable.getRowCount() > 0 && outputDirectoryField.getText().length() > 0) { convertButton.setEnabled(true); } } }
From source file:com.mirth.connect.client.ui.MessageImportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }//from ww w .j av a 2s .c o m } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:firmadigital.Firma.java
private void cmdExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarActionPerformed JFileChooser fileChooser = new JFileChooser(); txtUbicacion.setText(""); lblNombreArchivo.setText(""); lblRutaArchivo.setText(""); String signFileName = txtUbicacion.getText(); File directory = new File(signFileName).getParentFile(); fileChooser.setCurrentDirectory(directory); FileNameExtensionFilter filter; filter = new FileNameExtensionFilter("XML file", "xml"); fileChooser.setFileFilter(filter);/* w w w . jav a2 s . co m*/ fileChooser.setFileHidingEnabled(true); /*Remove All File option*/ fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacion.setText(selectedFile); lblNombreArchivo.setText(fileChooser.getSelectedFile().getName()); lblRutaArchivo.setText(fileChooser.getSelectedFile().getParent()); } }
From source file:DOMTreeTest.java
/** * Open a file and load the document. *///from w w w . j av a 2s. c o m public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml"); } public String getDescription() { return "XML files"; } }); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; final File file = chooser.getSelectedFile(); new SwingWorker<Document, Void>() { protected Document doInBackground() throws Exception { if (builder == null) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); } return builder.parse(file); } protected void done() { try { Document doc = get(); JTree tree = new JTree(new DOMTreeModel(doc)); tree.setCellRenderer(new DOMTreeCellRenderer()); setContentPane(new JScrollPane(tree)); validate(); } catch (Exception e) { JOptionPane.showMessageDialog(DOMTreeFrame.this, e); } } }.execute(); }
From source file:gui.QTLResultsPanel.java
void saveTXT() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Prefs.gui_dir)); fc.setDialogTitle("Save QTL Results"); while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Make sure it has an appropriate extension if (!file.exists()) { if (file.getName().indexOf(".") == -1) { file = new File(file.getPath() + ".csv"); }/*from w w w.j av a 2 s.c o m*/ } // Confirm overwrite if (file.exists()) { int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1); if (response == JOptionPane.NO_OPTION) { continue; } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) { return; } } // Otherwise it's ok to save... Prefs.gui_dir = "" + fc.getCurrentDirectory(); saveTXTFile(file); return; } }