List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
From source file:net.sf.jabref.exporter.ExportFormats.java
private static JFileChooser createExportFileChooser(String currentDir) { String lastUsedFormat = Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT); FileFilter defaultFilter = null; JFileChooser fc = new JFileChooser(currentDir); Set<FileFilter> filters = new TreeSet<>(); for (Map.Entry<String, IExportFormat> e : ExportFormats.EXPORT_FORMATS.entrySet()) { String formatName = e.getKey(); IExportFormat format = e.getValue(); filters.add(format.getFileFilter()); if (formatName.equals(lastUsedFormat)) { defaultFilter = format.getFileFilter(); }//from w ww .jav a2 s .c o m } for (FileFilter ff : filters) { fc.addChoosableFileFilter(ff); } fc.setAcceptAllFileFilterUsed(false); if (defaultFilter != null) { fc.setFileFilter(defaultFilter); } return fc; }
From source file:ImageFileFilterImageScale.java
private String getImageFile() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new ImageFilter()); int result = fc.showOpenDialog(null); File file = null;/* w w w .ja va 2 s .c om*/ if (result == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); return file.getPath(); } else return null; }
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(); }//from ww w. ja v a 2s . com 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:ImageViewer.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == openItem) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory(); }//from www . j a va2 s . c o m public String getDescription() { return "GIF Images"; } }); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String name = chooser.getSelectedFile().getName(); label.setIcon(new ImageIcon(name)); } } else if (source == exitItem) System.exit(0); }
From source file:ec.util.chart.swing.Charts.java
public static void saveChart(@Nonnull ChartPanel chartPanel) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileFilter defaultFilter = new FileNameExtensionFilter("PNG (.png)", "png"); fileChooser.addChoosableFileFilter(defaultFilter); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG (.jpg) (.jpeg)", "jpg", "jpeg")); if (Charts.canWriteChartAsSVG()) { fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG (.svg)", "svg")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Compressed SVG (.svgz)", "svgz")); }//from ww w .j av a2 s . c o m fileChooser.setFileFilter(defaultFilter); File currentDir = chartPanel.getDefaultDirectoryForSaveAs(); if (currentDir != null) { fileChooser.setCurrentDirectory(currentDir); } if (fileChooser.showSaveDialog(chartPanel) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try (OutputStream stream = Files.newOutputStream(file.toPath())) { writeChart(getMediaType(file), stream, chartPanel.getChart(), chartPanel.getWidth(), chartPanel.getHeight()); } chartPanel.setDefaultDirectoryForSaveAs(fileChooser.getCurrentDirectory()); } }
From source file:cc.creativecomputing.io.CCIOUtil.java
/** * Opens a platform-specific file chooser dialog to select a file for input. This function returns the full path to * the selected file as a <b>String</b>, or <b>null</b> if no selection. Files are filtered according to the given * file extensions./*w ww. jav a 2s . c om*/ * * @webref input:files * @param theExtensions file extensions for filtering * @return full path to the selected file, or null if canceled. * * @see #selectOutput(String) * @see #selectFolder(String) */ static public String selectFilteredInput(String... theExtensions) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new CCFileExtensionFilter(theExtensions)); fileChooser.setDialogTitle("Select a file..."); int returned = fileChooser.showOpenDialog(null); if (returned == JFileChooser.CANCEL_OPTION) { selectedFile = null; } else { selectedFile = fileChooser.getSelectedFile(); } return (selectedFile == null) ? null : selectedFile.getAbsolutePath(); }
From source file:csv.to.sql.parser.mainMenu.java
private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileActionPerformed // TODO add your handling code here: JFileChooser myFile = new JFileChooser(); myFile.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); myFile.showOpenDialog(this); this.selectedFile = myFile.getSelectedFile(); if (this.selectedFile.exists()) { this.fileSelected = true; this.lblFile.setText(this.selectedFile.getName()); this.btnOpenFile.setEnabled(false); this.btnParse.setEnabled(true); } else {/*from www. j av a 2 s. co m*/ JOptionPane.showInternalMessageDialog(this, "The file doesn't exists!"); } }
From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java
PhotoCaptureFrame() { jp = new JPanel(); jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(jp); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117)); JButton btn = new JButton("Upload Image"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(System.getenv("user.home")); fc.setFileFilter(new JPEGImageFileFilter()); int res = fc.showOpenDialog(null); // We have an image! try { if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //SharedResources.sharedCache.getCapturedImageList().add(file); File tmpf_name = File.createTempFile("tmp", "." + FilenameUtils.getExtension(file.getName())); System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); }//from ww w.j a v a2 s. co m } catch (Exception iOException) { } } }); ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0"); ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT); ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13)); ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0"); ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT); ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13)); appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id); appIDLabel.setHorizontalAlignment(SwingConstants.LEFT); appIDLabel.setFont(new Font("Arial", Font.BOLD, 13)); headerPanel = new JPanel(new FlowLayout()); headerPanel.add(ImageRemainingProcessingLabel); headerPanel.add(ImagebeingProcessedLabel); headerPanel.add(btn); headerPanel.add(appIDLabel); headerPanel.setSize(new Dimension(getWidth(), 10)); JPanel contentPane = new JPanel(); contentPane.add(headerPanel); contentPane.add(scrollPane); f = new JFrame("IBM Watson Visual Prediction Window"); f.setContentPane(contentPane); f.setSize(dim.width / 2 - 30, dim.height - 40); f.setLocation(dim.width / 2, 0); f.setResizable(false); f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60)); f.setVisible(true); }
From source file:com.codecrate.shard.ui.form.BioForm.java
protected JComponent createFormControl() { SwingBindingFactory bindingFactory = (SwingBindingFactory) getBindingFactory(); JFileChooser fileChooser = new JFileChooser(); DefaultFileFilter filter = new DefaultFileFilter(); filter.addExtension("jpg"); filter.addExtension("gif"); filter.addExtension("png"); fileChooser.setFileFilter(filter); TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory()); formBuilder.add("bio.name"); formBuilder.row();/*from w w w. ja v a2 s. com*/ formBuilder.add(new JFileChooserBinding(getFormModel(), "bio.portraitFile", fileChooser)); formBuilder.row(); formBuilder.add("bio.height"); formBuilder.row(); formBuilder.add("bio.weight"); formBuilder.row(); formBuilder.addInScrollPane(bindingFactory.createBoundTextArea("bio.backstory", 5, 0)); return formBuilder.getForm(); }
From source file:storybook.ui.chart.AbstractChartPanel.java
private AbstractAction getExportAction() { if (this.exportAction == null) { this.exportAction = new AbstractAction() { @Override//w w w . ja v a 2s .c om 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; }