List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:osu.beatmapdownloader.JFrame.java
private void B_DirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_DirectoryActionPerformed JFileChooser chooser; chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("Open Osu! Installation Directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File route = chooser.getSelectedFile(); if (route.toString().endsWith("Songs")) { Directory = route.getAbsolutePath(); T_Directory.setText(Directory); } else { if (route.isDirectory()) { String[] Files = route.list(); boolean found = false; for (String f : Files) if (f.contains("Songs")) { Directory = route + File.separator + f; T_Directory.setText(Directory); set("SongDirectory", Directory); found = true; break; }//from ww w . j av a 2 s . co m if (found == false) Alert("Incorrect Osu! Directory"); } } } }
From source file:pcgen.gui2.converter.panel.WriteDirectoryPanel.java
@Override public void setupDisplay(JPanel panel, final CDOMObject pc) { panel.setLayout(layout);//ww w. j ava 2 s.com Component label = new JLabel("Please select the Directory where Converted files should be written: "); AbstractButton button = new JButton("Browse..."); button.setMnemonic('r'); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(path.getParentFile()); chooser.setSelectedFile(path); while (true) { int open = chooser.showOpenDialog(null); if (open == JFileChooser.APPROVE_OPTION) { File fileToOpen = chooser.getSelectedFile(); if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) { path = fileToOpen; pc.put(ObjectKey.WRITE_DIRECTORY, path); fileLabel.setText(path.getAbsolutePath()); PCGenSettings context = PCGenSettings.getInstance(); context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath()); showWarning(); break; } JOptionPane.showMessageDialog(null, "Selection must be a valid " + "(readable & writeable) Directory"); chooser.setCurrentDirectory(path.getParentFile()); } else if (open == JFileChooser.CANCEL_OPTION) { break; } } } }); panel.add(label); panel.add(fileLabel); panel.add(button); panel.add(warningLabel); showWarning(); layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel); layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel); fileLabel.setText(path.getAbsolutePath()); }
From source file:pcgen.gui2.dialog.ExportDialog.java
private void export(boolean pdf) { UIPropertyContext context = UIPropertyContext.createContext("ExportDialog"); final JFileChooser fcExport = new JFileChooser(); fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY); File baseDir = null;//from w w w .j a v a 2s. c o m { String path; if (pdf) { path = context.getProperty(PDF_EXPORT_DIR_PROP); } else { path = context.getProperty(HTML_EXPORT_DIR_PROP); } if (path != null) { baseDir = new File(path); } } if (baseDir == null || !baseDir.isDirectory()) { baseDir = SystemUtils.getUserHome(); } fcExport.setCurrentDirectory(baseDir); URI uri = fileList.getSelectedValue(); String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf); if (pdf) { FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("xml".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else { String desc = extension + " Files (*." + extension + ")"; fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension)); } String name; File path; if (!partyBox.isSelected()) { CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem(); path = character.getFileRef().get(); if (path != null) { path = path.getParentFile(); } else { path = new File(PCGenSettings.getPcgDir()); } name = character.getTabNameRef().get(); if (StringUtils.isEmpty(name)) { name = character.getNameRef().get(); } } else { path = new File(PCGenSettings.getPcgDir()); name = "Entire Party"; } if (pdf) { fcExport.setSelectedFile(new File(path, name + ".pdf")); } else { fcExport.setSelectedFile(new File(path, name + "." + extension)); } fcExport.setDialogTitle("Export " + name); if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { return; } final File outFile = fcExport.getSelectedFile(); if (pdf) { context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent()); } else { context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent()); } if (StringUtils.isEmpty(outFile.getName())) { pcgenFrame.showErrorMessage("PCGen", "You must set a filename."); return; } if (outFile.isDirectory()) { pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file."); return; } if (outFile.exists() && !SettingsHandler.getAlwaysOverwrite()) { int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION); if (reallyClose != JOptionPane.YES_OPTION) { return; } } if (pdf) { new PDFExporter(outFile, extension, name).execute(); } else { if (!printToFile(outFile)) { String message = "The character export failed. Please see the log for details."; pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message); return; } maybeOpenFile(outFile); Globals.executePostExportCommandStandard(outFile.getAbsolutePath()); } }
From source file:pdfreader.PDFReader.java
public void convertToStandardHtml() { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); // String typee = JOptionPane.showInputDialog("Type","3"); // int type = Integer.parseInt(typee); // String zooom = JOptionPane.showInputDialog("Zoom","2"); // int zoom = new Float(zooom); // System.out.println(type+"<---type and zoom--->"+zoom); try {// ww w .j a va2 s . c o m // HtmFile htmlFile = new HtmFile(outputFileName, type, zoom); // StandardHtml shtml = new StandardHtml(outputFileName, 3, 2); // shtml.convertPdfToHtml(name); // shtml.closeFile(); HtmlFile htmlFile; htmlFile = new HtmlFile(outputFileName, 3, 2); htmlFile.convertPdfToHtml(name); htmlFile.endTable();//used for spanning htmlFile.getAllCell();//used for spanning htmlFile.closeFile(); } catch (Exception e) { System.err.println("Filed to convert Pdf to Html."); e.printStackTrace(); } }
From source file:pdfreader.PDFReader.java
public void regionTextAllOnce(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); File saveFile1 = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); String outputFileName1;//from w ww . j a v a 2 s . c o m outputFileName1 = saveFile1.toString().substring(0, (saveFile1.toString().length() - 5)) + ".xml"; HtmlFileGen htmlFileGen = new HtmlFileGen(name, "C:\\blazeds\\tomcat\\webapps\\pictures\\", "localhost:8080/pictures/", getTheFileName(name), ""); TaggedRegion tr; BufferedWriter xmlFile = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outputFileName1), "UTF8")); xmlFile.write("<?xml version=\"1.0\"?><Pages>"); int tempPageNumber = -1; try (BufferedWriter htmlFile = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outputFileName), "UTF8"))) { for (int i = 0; i < listOfSelectedRegionInRectangle.size(); i++) { tr = listOfSelectedRegionInRectangle.get(i); if (tempPageNumber == -1) xmlFile.write("<Page No = \"" + tr.pageNumber + "\">"); else if (tempPageNumber != tr.pageNumber) xmlFile.write("</Page><Page No = \"" + tr.pageNumber + "\">"); // else // xmlFile.write("<Page No = \""+tr.pageNumber+"\">"); tempPageNumber = tr.pageNumber; String s = htmlFileGen.getHtmlContent(tr.pageNumber, tr.rectangle, tr.tag); if ("table".equals(tr.tag) || "list".equals(tr.tag)) { twoDRect = htmlFileGen.twoDRect; } htmlFile.write(s); xmlFile.write("<Region x = \"" + tr.rectangle.x + "\" y = \"" + tr.rectangle.y + "\" height = \"" + tr.rectangle.height + "\" width = \"" + tr.rectangle.width + "\" type = \"" + tr.tag + "\">"); xmlFile.write("<HtmlContent>" + StringEscapeUtils.escapeXml(s) + "</HtmlContent></Region>"); // System.out.println(s); } } xmlFile.write("</Page></Pages>"); xmlFile.close(); listOfSelectedRegionInRectangle = new ArrayList<>(); }
From source file:pdfreader.PDFReader.java
private void listExtract(java.awt.event.ActionEvent evt) { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); try {//from ww w .j a v a2 s.c om ListExtraction list = new ListExtraction(outputFileName, 2, 2); PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition(true); stripper.addRegion("class1", rectangle); List allPages = document.getDocumentCatalog().getAllPages(); PDPage firstPage = (PDPage) allPages.get(currentPage); stripper.extractRegions(firstPage); System.out.println("Text in the area:" + rectangle); String region = stripper.getTextForRegion("class1"); System.out.println(region); List<TextPosition> TextinArea = stripper.getAllSelectedText(); for (Iterator<TextPosition> it = TextinArea.iterator(); it.hasNext();) { TextPosition text = it.next(); list.processTextt(text); } // list.endOfTable(); list.closeFile(); } catch (Exception e) { System.err.println("Filed to convert Pdf to Html."); } }
From source file:pdfreader.PDFReader.java
private void converttoTable(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("G:/From Fuad sir DOCX to PDF"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); int[] regioon = null; ExtractTextByArea ETB = new ExtractTextByArea(); try {/*from w ww. j a v a 2s . c o m*/ regioon = ETB.extractTextByArea(name, rectangle, currentPage, 0); } catch (IOException | CryptographyException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } int positionOfRowStart[] = ETB.getPointOfRowStart(); int numberofRows = ETB.returnNumberofRows(); int numberofColumns = ETB.returnNumberofColumns(); ExtractTextByColumn ETBC = new ExtractTextByColumn(); Rectangle[] ColumnWiseRect = new Rectangle[(numberofColumns - 1) * numberofRows]; int q = 0; for (int row = 0; row <= numberofRows - 1; row++) { for (int column = 0; column < numberofColumns - 1; column++) { if (column == 0 && row == 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, rectangle.y, (regioon[column + 1] * 5 - rectangle.x) - 2, positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(rectangle.x,rectangle.y,(regioon[column+1]*5-rectangle.x)-2,positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (row == 0 && column > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, rectangle.y, (regioon[column + 1] * 5 - regioon[column] * 5), positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(regioon[column]*5-2,rectangle.y,(regioon[column+1]*5-regioon[column]*5),positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column == 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - rectangle.x), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(rectangle.x,positionOfRowStart[row-1]+2,(regioon[column+1]*5-rectangle.x),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column > 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - regioon[column] * 5), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(regioon[column]*5-2,positionOfRowStart[row-1]+2,(regioon[column+1]*5-regioon[column]*5),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } q++; } } // pdfPagePanel.pdfpagepanelrec = ColumnWiseRect; // try { // ETBC.getTable(numberofRows,numberofColumns,saveFile,true); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } }
From source file:pdfreader.PDFReader.java
private void converttoList(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("G:/From Fuad sir DOCX to PDF"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); int[] regioon = null; ExtractTextByArea ETB = new ExtractTextByArea(); try {//www. j a v a 2s .c om regioon = ETB.extractTextByArea(name, rectangle, currentPage, 0); } catch (IOException | CryptographyException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } int positionOfRowStart[] = ETB.getPointOfRowStart(); int numberofRows = ETB.returnNumberofRows(); int numberofColumns = ETB.returnNumberofColumns(); ExtractTextByColumn ETBC = new ExtractTextByColumn(); Rectangle[] ColumnWiseRect = new Rectangle[(numberofColumns - 1) * numberofRows]; int q = 0; for (int row = 0; row <= numberofRows - 1; row++) { for (int column = 0; column < numberofColumns - 1; column++) { if (column == 0 && row == 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, rectangle.y, (regioon[column + 1] * 5 - rectangle.x) - 2, positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(rectangle.x,rectangle.y,(regioon[column+1]*5-rectangle.x)-2,positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (row == 0 && column > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, rectangle.y, (regioon[column + 1] * 5 - regioon[column] * 5), positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(regioon[column]*5-2,rectangle.y,(regioon[column+1]*5-regioon[column]*5),positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column == 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - rectangle.x), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(rectangle.x,positionOfRowStart[row-1]+2,(regioon[column+1]*5-rectangle.x),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column > 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - regioon[column] * 5), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(regioon[column]*5-2,positionOfRowStart[row-1]+2,(regioon[column+1]*5-regioon[column]*5),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } q++; } } //pdfPagePanel.pdfpagepanelrec = ColumnWiseRect; try { ETBC.getList(numberofRows, numberofColumns, saveFile); } catch (IOException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:phex.gui.common.FileDialogHandler.java
private static JFileChooser initDefaultChooser(String title, String approveBtnText, char approveBtnMnemonic, FileFilter filter, int mode, File currentDirectory, String notifyPopupTitle, String notifyPopupShortMessage) { JFileChooser chooser = new JFileChooser(); if (notifyPopupTitle != null || notifyPopupShortMessage != null) { displayNotificationPopup(chooser, notifyPopupTitle, notifyPopupShortMessage); }//from w w w . j a v a 2 s . co m if (currentDirectory != null) { chooser.setCurrentDirectory(currentDirectory); } if (filter != null) { chooser.setFileFilter(filter); } chooser.setFileSelectionMode(mode); chooser.setDialogTitle(title); chooser.setApproveButtonText(approveBtnText); chooser.setApproveButtonMnemonic(approveBtnMnemonic); return chooser; }
From source file:processing.app.Base.java
static public File selectFolder(String prompt, File folder, Component parent) { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(prompt);/*from w w w. ja v a2s. co m*/ if (folder != null) { fc.setSelectedFile(folder); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returned = fc.showOpenDialog(parent); if (returned == JFileChooser.APPROVE_OPTION) { return fc.getSelectedFile(); } return null; }