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:cmsc105_mp2.Plot.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try {// ww w .j a v a2 s. co m ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { System.out.println("Unable to Print!"); } } }
From source file:ZipTest.java
public ZipTestFrame() { setTitle("ZipTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add the menu and the Open and Exit menu items JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); menu.add(openItem);//from w w w.j a va 2 s . c o m openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(ZipTestFrame.this); if (r == JFileChooser.APPROVE_OPTION) { zipname = chooser.getSelectedFile().getPath(); fileCombo.removeAllItems(); scanZipFile(); } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); menuBar.add(menu); setJMenuBar(menuBar); // add the text area and combo box fileText = new JTextArea(); fileCombo = new JComboBox(); fileCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadZipFile((String) fileCombo.getSelectedItem()); } }); add(fileCombo, BorderLayout.SOUTH); add(new JScrollPane(fileText), BorderLayout.CENTER); }
From source file:ImageIOTest.java
/** * Save the current image in a file/*from w w w .j a va2s. c o m*/ * @param formatName the file format */ public void saveFile(final String formatName) { if (images == null) return; Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(formatName); ImageWriter writer = iter.next(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); String[] extensions = writer.getOriginatingProvider().getFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions)); int r = chooser.showSaveDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); try { ImageOutputStream imageOut = ImageIO.createImageOutputStream(f); writer.setOutput(imageOut); writer.write(new IIOImage(images[0], null, null)); for (int i = 1; i < images.length; i++) { IIOImage iioImage = new IIOImage(images[i], null, null); if (writer.canInsertImage(i)) writer.writeInsert(i, iioImage, null); } } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } }
From source file:ImageIOTest.java
/** * Open a file and load the images.//from ww w . j av a 2 s . 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; File f = chooser.getSelectedFile(); Box box = Box.createVerticalBox(); try { String name = f.getName(); String suffix = name.substring(name.lastIndexOf('.') + 1); Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix); ImageReader reader = iter.next(); ImageInputStream imageIn = ImageIO.createImageInputStream(f); reader.setInput(imageIn); int count = reader.getNumImages(true); images = new BufferedImage[count]; for (int i = 0; i < count; i++) { images[i] = reader.read(i); box.add(new JLabel(new ImageIcon(images[i]))); } } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } setContentPane(new JScrollPane(box)); validate(); }
From source file:ImageProcessingTest.java
/** * Open a file and load the image.// w w w. j a va2 s . 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:PreferencesTest.java
public PreferencesFrame() { // get position, size, title from preferences Preferences root = Preferences.userRoot(); final Preferences node = root.node("/com/horstmann/corejava"); int left = node.getInt("left", 0); int top = node.getInt("top", 0); int width = node.getInt("width", DEFAULT_WIDTH); int height = node.getInt("height", DEFAULT_HEIGHT); setBounds(left, top, width, height); // if no title given, ask user String title = node.get("title", ""); if (title.equals("")) title = JOptionPane.showInputDialog("Please supply a frame title:"); if (title == null) title = ""; setTitle(title);//www . ja v a 2s . co m // set up file chooser that shows XML files final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); // accept all files ending with .xml chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); } public String getDescription() { return "XML files"; } }); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem exportItem = new JMenuItem("Export preferences"); menu.add(exportItem); exportItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { OutputStream out = new FileOutputStream(chooser.getSelectedFile()); node.exportSubtree(out); out.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem importItem = new JMenuItem("Import preferences"); menu.add(importItem); importItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { InputStream in = new FileInputStream(chooser.getSelectedFile()); Preferences.importPreferences(in); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { node.putInt("left", getX()); node.putInt("top", getY()); node.putInt("width", getWidth()); node.putInt("height", getHeight()); node.put("title", getTitle()); System.exit(0); } }); }
From source file:de.atomfrede.tools.evalutation.tools.plot.ui.wizard.time.pages.TimeFileSelectionPage.java
@Override public JButton getSelectInputFileButton() { if (selectInputFileButton == null) { selectInputFileButton = new JButton(Icons.IC_MIME_CSV_SMALL); selectInputFileButton.setText("Select Data File"); selectInputFileButton.addActionListener(new ActionListener() { @Override/*from w w w .j av a 2s . c om*/ public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub JFileChooser fc = getFileChooser(); if (dataFile != null) fc.setCurrentDirectory(dataFile.getParentFile()); int returnValue = fc.showOpenDialog(parent); if (returnValue == JFileChooser.APPROVE_OPTION) { dataFile = fc.getSelectedFile(); getInputFileTextField().setText(dataFile.getName()); // TODO check if that file contains a time column if (checkFile()) { plotWizard.setDataFile(dataFile); } else { plotWizard.setDataFile(null); } } } }); } return selectInputFileButton; }
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();//from w w w . j a va 2 s . c o m } }
From source file:cmsc105_mp2.Panels.java
public void createGraph(Data d, float window, Double threshold) { XYSeries data = new XYSeries("data"); double max = Double.MIN_VALUE; for (double num : d.plots) { if (max < num) max = num;/*from ww w . j a v a 2 s .co m*/ } max += 1; ArrayList<XYSeries> xy = new ArrayList(); ArrayList<Integer> points = new ArrayList(); for (int j = (int) (window / 2); j < d.plots.length - (window / 2); j++) { data.add(j, d.plots[j]); //System.out.println(points.size()); if (d.plots[j] > threshold) { points.add(j); } else { if (points.size() >= window) { //System.out.println("MIN!"); XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } points = new ArrayList(); } } if (points.size() >= window) { XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } XYSeriesCollection my_data_series = new XYSeriesCollection(); my_data_series.addSeries(data); for (XYSeries x : xy) { my_data_series.addSeries(x); } XYSeries thresh = new XYSeries("threshold"); for (int j = 0; j < d.plots.length; j++) { thresh.add(j, threshold); } my_data_series.addSeries(thresh); //System.out.println(d.name); JFreeChart XYLineChart = ChartFactory.createXYLineChart(d.name, "Position", "Average", my_data_series, PlotOrientation.VERTICAL, true, true, false); bImage1 = (BufferedImage) XYLineChart.createBufferedImage(690, 337); imageIcon = new ImageIcon(bImage1); jLabel1.setIcon(imageIcon); jLabel1.revalidate(); jLabel1.repaint(); jButton1.setText("Save as PNG"); jButton1.repaint(); jButton1.revalidate(); jButton1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try { ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { System.out.println("Unable to Print!"); } } } }); }
From source file:Result3.java
public void createImage() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try {/*from w w w . java 2s.c om*/ ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { Logger.getLogger(Result1.class.getName()).log(Level.SEVERE, null, ex); } } }