List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:JuliaSet3.java
public void save() throws IOException { // Find a factory object for printing Printable objects to PostScript. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; String format = "application/postscript"; StreamPrintServiceFactory factory = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, format)[0];/*from w w w .j a v a2 s . co m*/ // Ask the user to select a file and open the selected file JFileChooser chooser = new JFileChooser(); if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); FileOutputStream out = new FileOutputStream(f); // Obtain a PrintService that prints to that file StreamPrintService service = factory.getPrintService(out); // Do the printing with the method below printToService(service, null); // And close the output file. out.close(); }
From source file:MyFilterChooser.java
public MyFilterChooser() { super("Filter Test Frame"); setSize(350, 200);/* w w w . ja v a2s . c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); final JLabel statusbar = new JLabel("Output of your selection will go here"); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String[] pics = new String[] { "gif", "jpg", "tif" }; String[] audios = new String[] { "au", "aiff", "wav" }; JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(new SimpleFileFilter(pics, "Images (*.gif, *.jpg, *.tif)")); chooser.addChoosableFileFilter(new SimpleFileFilter(".MOV")); chooser.addChoosableFileFilter(new SimpleFileFilter(audios, "Sounds (*.aiff, *.au, *.wav)")); int option = chooser.showOpenDialog(MyFilterChooser.this); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) statusbar.setText("You chose " + chooser.getSelectedFile().getName()); } else { statusbar.setText("You canceled."); } } }); c.add(openButton); c.add(statusbar); setVisible(true); }
From source file:com.itd.dbmrgdao.TestTime_newscanner.java
@Ignore @org.junit.Test/*from w w w . j a va 2 s . com*/ public void test() throws ParseException { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); String fileName = f.getAbsolutePath(); try { FileReader reader = new FileReader(fileName); BufferedReader br = new BufferedReader(reader); String strLine; Boolean result = updateScanFileRoundUp2(br); br.close(); } catch (IOException ex) { } }
From source file:org.spf4j.ui.TSDBViewJInternalFrame.java
@edu.umd.cs.findbugs.annotations.SuppressWarnings("UP_UNUSED_PARAMETER") private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed TreePath[] selectionPaths = measurementTree.getSelectionPaths(); List<String> selectedTables = getSelectedTables(selectionPaths); if (!selectedTables.isEmpty()) { JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { tsDb.writeCsvTables(selectedTables, file); } catch (IOException ex) { throw new RuntimeException(ex); }/*from ww w . ja v a 2s .c o m*/ } } }
From source file:com.petersoft.advancedswing.enhancedtextarea.EnhancedTextArea.java
private void jSaveButtonActionPerformed(ActionEvent evt) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); CommonLib.saveFile(this.jTextArea.getText(), file); }/*from w w w . ja va 2s. c o m*/ }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a file (path)./*w ww. j av a 2s .c o m*/ * * @param lang * language * @return chosen file path */ public String selectFile(NatLang lang) { JFileChooser fileChooser = new JFileChooser(lastFilePath); fileChooser.setLocale(lang.getLocale()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setToolTipText(lang.getText("selectFile")); fileChooser.setDialogTitle(lang.getText("selectFile")); fileChooser.showDialog(null, lang.getText("selectFile")); File f = fileChooser.getSelectedFile(); if (f != null) { lastFilePath = f.getPath(); return lastFilePath; } else { return null; } }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
protected void openConfig() { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showOpenDialog = fileChooser.showOpenDialog(this); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { configHandler.setConfigFile(fileChooser.getSelectedFile().getAbsolutePath()); getProxyConfigPanel().update();// w ww . j av a 2s .c om } }
From source file:ImageProcessingTest.java
/** * Open a file and load the image.//from w w w.j a va 2s. c o m */ public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); String[] extensions = ImageIO.getReaderFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions)); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; try { Image img = ImageIO.read(chooser.getSelectedFile()); image = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); image.getGraphics().drawImage(img, 0, 0, null); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } repaint(); }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == openItem) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".zip") || f.isDirectory(); }/* w w w . j av a2 s. c o m*/ public String getDescription() { return "ZIP Files"; } }); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String zipname = chooser.getSelectedFile().getPath(); System.out.println(zipname); } } else if (source == exitItem) System.exit(0); }
From source file:it.unibas.spicygui.controllo.file.ActionOpenMappingTask.java
@Override public void performAction() { this.executeInjection(); JFileChooser chooser = vista.getFileChooserApriXMLAndTGD(); File file;//from w ww. j a va 2 s.co m int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); Scenario scenario = null; if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); String fileAbsoluteFile = file.getPath(); scenario = openCompositionFile(fileAbsoluteFile, file, true); MappingTask mappingTask = scenario.getMappingTask(); File f = chooser.getSelectedFile(); FileObject fo = FileUtil.toFileObject(f); // TGDDataObject dobj = null; try { TGDEditorSupport tGDEditorSupport = new TGDEditorSupport(fo); // dobj = tGDEditorSupport.getDataObject(); tGDEditorSupport.open(); //giannisk scenario.setTGDEditor(tGDEditorSupport); scenario.getMappingTaskTopComponent().requestActive(); // dobj = DataObject.find(fo); } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } //if (dobj != null){ // OpenCookie lc = (OpenCookie)dobj.getCookie(OpenCookie.class); // if (lc == null) {/* cannot do it */ return;} // lc.open(); //// Line l = lc.getLineSet().getOriginal(lineNumber); //// l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS); //} //try { // Editor.getDefaultLocale(). //// new ROEditor(fo).open(); // // new TGDEditorSupport(fo).edit(); // //// DataObject dataObject = new ROEditor(fo).getDataObject(); //// //// EditorCookie cookie = (EditorCookie)dataObject.getCookie(EditorCookie.class); //// cookie.open(); // // System.out.println("eseguito"); //} catch (DataObjectNotFoundException e) { // e.printStackTrace(); //} // if (!(mappingTask.getSourceProxy() instanceof ConstantDataSourceProxy)) { // Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); scenario.setCompositionTopComponent(new CompositionTopComponent(scenario)); actionComposition.performAction(); } } }