List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:ImageIOTest.java
/** * Open a file and load the images./*from w w w .ja v a 2 s. co 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:graph.plotter.PieMenu.java
/** * This method works for choosing file path /*from w w w. java2 s. co m*/ */ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: JFileChooser jf = new JFileChooser(); jf.showOpenDialog(null); File file = jf.getSelectedFile(); String f = file.getAbsolutePath(); jTextField3.setText(f); }
From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java
private String choosePath(String pfad) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pfad)); chooser.setDialogTitle("DB Pfad"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null : chooser.getSelectedFile().getPath() + File.separator; }
From source file:graph.plotter.BarMenu.java
/** * This method works for choosing file path //from w w w. j a va 2 s . c o m */ private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed JFileChooser jf = new JFileChooser(); jf.showOpenDialog(null); File file = jf.getSelectedFile(); String f = file.getAbsolutePath(); jTextField3.setText(f); }
From source file:com.itd.dbmrgdao.TestTime7.java
@Ignore @org.junit.Test// w w w. j av a 2 s . c o m public void test() throws ParseException { String newTab = "\t"; String[] sysidLine; 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; String sysid = null, scdate = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null, otEnd = null; String scode = "1985"; StringBuilder insertSQL = new StringBuilder( "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p2end) VALUES "); StringBuilder deleteSQL = new StringBuilder("DELETE FROM scandata WHERE (sc_sysid,scdate) IN ("); // read from select file for (strLine = br.readLine(); strLine != null; strLine = br.readLine()) { System.out.println(strLine); } while ((strLine = br.readLine()) != null) { String[] parts = strLine.split(" "); // check if not first record or sysid change will save in table scandata if (sysid != null && !sysid.equals(parts[0])) { deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'),"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("'),"); p1Start = null; p1End = null; p2Start = null; p2End = null; otStart = null; otEnd = null; } //clear sysid = parts[0]; scdate = new StringBuffer(parts[1]).insert(parts[1].length() - 2, "-").toString(); scdate = new StringBuffer(scdate).insert(scdate.length() - 5, "-").toString(); String timeString = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, timeString, "01"); } else { p2End = CompareTime(p2End, timeString, "04"); } } deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'))"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("')"); scanDao.executeSQL(deleteSQL.toString()); scanDao.executeSQL(insertSQL.toString()); br.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:ImageProcessingTest.java
/** * Open a file and load the image.//from ww w . j a v 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; 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:fusion.Fusion.java
private static void setSameAsLinksFile() throws IOException { JFileChooser dialogue = new JFileChooser(new File(".")); File fichier;/* ww w . j a va2s. c o m*/ if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { fichier = dialogue.getSelectedFile(); sameAsLinksFile = fichier.getPath(); } }
From source file:fusion.Fusion.java
private static void setDatasetFile1() throws IOException { JFileChooser dialogue = new JFileChooser(new File(".")); File fichier;//from ww w .j a v a2 s. c o m if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { fichier = dialogue.getSelectedFile(); datasetFile1 = fichier.getPath(); } }
From source file:fusion.Fusion.java
private static void setDatasetFile2() throws IOException { JFileChooser dialogue = new JFileChooser(new File(".")); File fichier;/* w w w . j a va 2 s .c o m*/ if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { fichier = dialogue.getSelectedFile(); datasetFile2 = fichier.getPath(); } }
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void promptForGradleBaseDir() { JFileChooser c = new JFileChooser(); c.setDialogTitle(//from ww w.j av a 2 s. co m "Pick the top level directory to use when viewing dependencies (in case you have a multi-module project)"); c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = c.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { gradleBaseDir = c.getSelectedFile().getPath(); } }