List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:com.apatar.ui.JPublishToApatarDialog.java
private void createListeners() { browse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir")); fileChooser.setMultiSelectionEnabled(false); int returnValue = fileChooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { File fileSrc = fileChooser.getSelectedFile(); nameFile.setText(fileSrc.getPath()); }/*from w w w .j av a 2 s. co m*/ } }); bCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { option = CANCEL_OPTION; setVisible(false); } }); bOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { option = OK_OPTION; setVisible(false); } }); selectFromFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (selectFromFile.isSelected()) { nameFile.setEnabled(true); browse.setEnabled(true); } else { nameFile.setEnabled(false); browse.setEnabled(false); } } }); autoGenerateShortDescription.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (autoGenerateShortDescription.isSelected()) setEnableShortDescription(false); else setEnableShortDescription(true); } }); }
From source file:net.sf.nmedit.nomad.core.Nomad.java
private File getExportFile() { JFileChooser chooser = new JFileChooser(); if (chooser.showSaveDialog(mainWindow) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); }//from w w w. j a va 2 s . c o m return null; }
From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java
private static JButton createBrowseButton(final boolean directoriesOnly, final String browserApproveButtonText, final JTextField textField, final FileFilter... fileFilters) { JButton browseButton = new JButton("..."); browseButton.addActionListener(new ActionListener() { @Override//from w ww . j av a 2s . com public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (textField.getText() != null) { File file = new File(textField.getText()); // if the file doesn't exist but the directory does, get that if (!file.exists() && file.getParentFile() != null && file.getParentFile().exists()) { file = file.getParentFile(); } if (!directoriesOnly && file.isFile()) { chooser.setSelectedFile(file); } if (file.isDirectory() && file.exists()) { chooser.setCurrentDirectory(file); } } if (directoriesOnly) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } // add filters and automatically select correct one if (fileFilters.length == 1) { chooser.setFileFilter(fileFilters[0]); } else { for (FileFilter filter : fileFilters) { chooser.addChoosableFileFilter(filter); if (filter instanceof FileNameExtensionFilter) { if (matchesFilter((FileNameExtensionFilter) filter, textField.getText())) { chooser.setFileFilter(filter); } } } } if (chooser.showDialog(textField, browserApproveButtonText) == JFileChooser.APPROVE_OPTION) { //File selected = processSelectedFile(chooser.getSelectedFile()); File selected = chooser.getSelectedFile(); String path = selected.getPath(); FileFilter filter = chooser.getFileFilter(); if (filter != null && filter instanceof FileNameExtensionFilter) { boolean found = matchesFilter(((FileNameExtensionFilter) chooser.getFileFilter()), path); if (!found) { String[] exts = ((FileNameExtensionFilter) chooser.getFileFilter()).getExtensions(); if (exts.length > 0) { path = FilenameUtils.removeExtension(path); path += "." + exts[0]; } } } textField.setText(path); } } }); return browseButton; }
From source file:pl.dpbz.poid.zadanie3.GUI.java
private String readSoundFile() { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("WAV sounds", "wav"); fc.addChoosableFileFilter(filter);//from w ww. j a v a2 s.c o m int returnVal = fc.showOpenDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); System.out.println("path: " + path); return path; }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX:/*from w w w.j a va 2 s.co m*/ System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:storybook.ui.chart.AbstractChartPanel.java
private AbstractAction getExportAction() { if (this.exportAction == null) { this.exportAction = new AbstractAction() { @Override//from w ww . java2s .c o m public void actionPerformed(ActionEvent paramAnonymousActionEvent) { try { Internal localInternal = BookUtil.get(AbstractChartPanel.this.mainFrame, SbConstants.BookKey.EXPORT_DIRECTORY, EnvUtil.getDefaultExportDir(AbstractChartPanel.this.mainFrame)); File localFile1 = new File(localInternal.getStringValue()); JFileChooser localJFileChooser = new JFileChooser(localFile1); localJFileChooser.setFileFilter(new PngFileFilter()); localJFileChooser.setApproveButtonText(I18N.getMsg("msg.common.export")); String str = AbstractChartPanel.this.mainFrame.getDbFile().getName() + " - " + AbstractChartPanel.this.chartTitle; str = IOUtil.cleanupFilename(str); localJFileChooser.setSelectedFile(new File(str)); int i = localJFileChooser.showDialog(AbstractChartPanel.this.getThis(), I18N.getMsg("msg.common.export")); if (i == 1) { return; } File localFile2 = localJFileChooser.getSelectedFile(); if (!localFile2.getName().endsWith(".png")) { localFile2 = new File(localFile2.getPath() + ".png"); } ScreenImage.createImage(AbstractChartPanel.this.panel, localFile2.toString()); JOptionPane.showMessageDialog(AbstractChartPanel.this.getThis(), I18N.getMsg("msg.common.export.success"), I18N.getMsg("msg.common.export"), 1); } catch (HeadlessException | IOException localException) { } } }; } return this.exportAction; }
From source file:frames.MainGUI.java
private File getSelectedFile() { // get file path FileFilter filter = new FileNameExtensionFilter("soccer data files", "csv"); JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); chooser.addChoosableFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else// w w w. j ava 2s . c o m return null; }
From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java
/** * This method initializes jExaminarButton * /*from w w w . j a v a 2s . c o m*/ * @return javax.swing.JButton */ private JButton getJExaminarButton() { if (jExaminarButton == null) { jExaminarButton = new JButton(); jExaminarButton.setText(I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_10)); jExaminarButton.setPreferredSize(new Dimension(90, 20)); jExaminarButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final JFileChooser libreria = new JFileChooser(); libreria.setDialogTitle(I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_11)); int returnVal = libreria.showOpenDialog(jPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { jLibreriaTextField.setText(libreria.getSelectedFile().toString()); } } }); } return jExaminarButton; }
From source file:localization.SplitterUI.java
private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null);/*from w w w. j a v a2s . co m*/ File f = chooser.getSelectedFile(); String filename = f.getAbsolutePath(); if (filename.endsWith(".lpu") || filename.endsWith(".zip")) { filepath.setText(filename); } else { JOptionPane.showMessageDialog(this, "The file type you select is not correct. ", "Upload File Issue", JOptionPane.ERROR_MESSAGE, null); return; } }
From source file:com.moteiv.trawler.Trawler.java
private void processEvent(AbstractButton source) { if (source == vLog) { if (source.isSelected()) { JFileChooser jfc = new JFileChooser(); File logFile;/* www . j ava 2s .c o m*/ int retval; retval = jfc.showSaveDialog(null); if (retval == JFileChooser.APPROVE_OPTION) { mif.setLogFile(jfc.getSelectedFile()); } else { vLog.setSelected(false); } } else { mif.setLogFile(null); } } else if (source == vLabels) { if (source.isSelected()) { pr.setVertexStringer(m_vs); } else { pr.setVertexStringer(new ConstantVertexStringer(null)); } } else if (source == vBlink) { if (source.isSelected()) { pr.setVertexColorFunction(new myVertexColorFunction(Color.RED.darker().darker(), Color.RED, 500)); ; } else { pr.setVertexPaintFunction( new PickableVertexPaintFunction(pr, Color.BLACK, Color.RED, Color.ORANGE)); } } else if (source == vSave) { if (source.isSelected()) { } else { } } else if (source == eLabels) { if (source.isSelected()) { pr.setEdgeStringer(m_es); } else { pr.setEdgeStringer(new ConstantEdgeStringer(null)); } } else if (source == eFilter) { if (source.isSelected()) { pr.setEdgeIncludePredicate(TruePredicate.getInstance()); } else { pr.setEdgeIncludePredicate(new myEdgeFilter()); } } else if (source == graphReset) { GraphIO.resetPrefs(g, layout, mif, Trawler.NODEFILE); } savePrefs(); }