List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:com.igormaznitsa.jhexed.swing.editor.ui.dialogs.hexeditors.DialogEditSVGImageValue.java
private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLoadActionPerformed final JFileChooser openDialog = new JFileChooser(lastOpenedFile); openDialog.setDialogTitle("Select SVG file"); openDialog.setAcceptAllFileFilterUsed(true); openDialog.setFileFilter(Utils.SVG_FILE_FILTER); if (openDialog.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { lastOpenedFile = openDialog.getSelectedFile(); try {/*ww w .j a v a 2 s . co m*/ final SVGImage img = new SVGImage(lastOpenedFile); this.value.setImage(img); this.panelPreview.removeAll(); this.panelPreview.add( new JLabel(new ImageIcon( img.rasterize(PREVIEW_SIZE, PREVIEW_SIZE, BufferedImage.TYPE_INT_ARGB))), BorderLayout.CENTER); this.panelPreview.revalidate(); this.panelPreview.repaint(); this.buttonOk.setEnabled(true); this.buttonSaveAs.setEnabled(true); } catch (IOException ex) { Log.error("Can't rasterize image [" + lastOpenedFile + ']', ex); JOptionPane.showMessageDialog(this, "Can't load the file, may be it is not a SVG file", "Can't load the file", JOptionPane.ERROR_MESSAGE); } } }
From source file:GUI.MyCustomFilter.java
private void OpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenActionPerformed if (projectSelected == 1) { JFileChooser chooser = new JFileChooser(); int chooserValue = chooser.showOpenDialog(this); if (chooserValue == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getAbsolutePath(); String ext = FilenameUtils.getExtension(path); if (ext.equalsIgnoreCase("cpp")) { try { fileSelected = 1;//from w w w. ja va 2 s . c om Scanner fin = new Scanner(chooser.getSelectedFile()); String buffer = ""; while (fin.hasNext()) { buffer += fin.nextLine() + "\n"; } textarea.setText(buffer); miniFile = path; jTextPane2.setText(path); //startButton.setVisible(true); } catch (FileNotFoundException ex) { //Logger.getLogger(TextEditorFrame.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, "Please input .cpp or .c extension file", "File Inaccessable", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(this, "Select New Project first", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:GUI.MyCustomFilter.java
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed if (projectSelected == 1) { JFileChooser chooser = new JFileChooser(); int chooserValue = chooser.showOpenDialog(this); if (chooserValue == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getAbsolutePath(); String ext = FilenameUtils.getExtension(path); if (ext.equalsIgnoreCase("cpp")) { try { fileSelected = 1;/*from w ww. j a v a2 s .c o m*/ Scanner fin = new Scanner(chooser.getSelectedFile()); String buffer = ""; while (fin.hasNext()) { buffer += fin.nextLine() + "\n"; } textarea.setText(buffer); miniFile = path; jTextPane2.setText(path); //startButton.setVisible(true); } catch (FileNotFoundException ex) { //Logger.getLogger(TextEditorFrame.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, "Please input .cpp or .c extension file", "File Inaccessable", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(this, "Select New Project first", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
public void addJpgMenuItem(final Component parent, JPopupMenu popMenu) { JMenuItem mItem = new JMenuItem("Save as JPG..."); mItem.addActionListener(new ActionListener() { @Override//from w w w .j a v a 2s . c o m public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); FileFilter filter1 = new SimpleFilter("jpg", "JPG File (*.jpg)"); chooser.addChoosableFileFilter(filter1); int status = chooser.showSaveDialog(parent); if (status == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); try { String fileName = f.getAbsolutePath().toLowerCase(); if (!fileName.endsWith("jpg")) fileName += ".jpg"; saveAsJPEG(new File(fileName)); } catch (IOException ex) { JOptionPane.showMessageDialog(parent, "IOException: Could not save file", "IOException", JOptionPane.ERROR_MESSAGE); } } } }); popMenu.add(mItem); }
From source file:networkanalyzer.NetworkAnalyzer.java
private void browseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browseMouseClicked JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("Browse the folder to process"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(true); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { String fileName = chooser.getSelectedFile().toString(); saveLoc.setText(fileName);//from w ww.j av a 2s. com } }
From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java
/** * Default constructor is required by Funambol Admin UI *///from ww w. j ava 2 s .c o m public Db4oSyncSourceConfigPanel() { setupControls(); // now we install our event handlers and we are ready to go... // handler to update the SyncClassConfigTree upon a change // in database file _dbFileLocateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final JFileChooser fc = new JFileChooser(); int rc = fc.showOpenDialog(Db4oSyncSourceConfigPanel.this); if (JFileChooser.APPROVE_OPTION == rc) { File f = fc.getSelectedFile(); _dbFileValue.setText(f.getPath()); Db4oSyncSourceConfigPanel.this.refreshClassConfigsFromFile(); } } catch (Exception ex) { StringWriter s = new StringWriter(); PrintWriter w = new PrintWriter(s); ex.printStackTrace(w); notifyError(new AdminException(s.toString())); } } }); // handler for the "Add" or "Update" button _confirmButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { validateValues(); updateSyncSource(); if (getState() == STATE_INSERT) { Db4oSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( Db4oSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand())); } else { Db4oSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( Db4oSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand())); } } catch (Exception e) { notifyError(new AdminException(e.getMessage())); } } }); }
From source file:net.sf.keystore_explorer.gui.actions.SignCsrAction.java
private File chooseCsrFile() { JFileChooser chooser = FileChooserFactory.getCsrFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("SignCsrAction.ChooseCsr.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("SignCsrAction.ChooseCsr.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File importFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(importFile); return importFile; }// w w w. j a va2s . co m return null; }
From source file:com.strath.view.MainGUI.java
private void projectSelectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_projectSelectMouseReleased JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int returnValue = chooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File directory = chooser.getSelectedFile(); String[] extensions = new String[1]; extensions[0] = "java"; selectedProject = listFiles(directory, extensions, true); isProjectSet = true;//from ww w. j a va2 s. c om } }
From source file:edu.clemson.lph.civet.addons.VspsCviFile.java
public void importVspsFile(Window parent) { String sVspsDir = CivetConfig.getVspsDirPath(); File fDir = new File(sVspsDir); JFileChooser open = new JFileChooser(fDir); Action details = open.getActionMap().get("viewTypeDetails"); details.actionPerformed(null);/* w w w . jav a2s . co m*/ open.setDialogTitle("Civet: Open PDF File"); open.setFileSelectionMode(JFileChooser.FILES_ONLY); open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); open.setMultiSelectionEnabled(false); int resultOfFileSelect = open.showOpenDialog(parent); if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) { File fIn = open.getSelectedFile(); saveme(parent, fIn); // vsps.printme(); } }
From source file:net.sf.keystore_explorer.gui.actions.ExamineFileAction.java
private File chooseFile() { JFileChooser chooser = FileChooserFactory.getCertFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("ExamineFileAction.ExamineFile.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("ExamineFileAction.ExamineFile.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File openFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(openFile); return openFile; }/* w ww. ja v a2 s . c om*/ return null; }