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:processing.app.Base.java
public void handleAddLibrary() { JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home")); fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add")); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip")); Dimension preferredSize = fileChooser.getPreferredSize(); fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200)); int returnVal = fileChooser.showOpenDialog(activeEditor); if (returnVal != JFileChooser.APPROVE_OPTION) { return;// w ww. ja v a2 s . c om } File sourceFile = fileChooser.getSelectedFile(); File tmpFolder = null; try { // unpack ZIP if (!sourceFile.isDirectory()) { try { tmpFolder = FileUtils.createTempFolder(); ZipDeflater zipDeflater = new ZipDeflater(sourceFile, tmpFolder); zipDeflater.deflate(); File[] foldersInTmpFolder = tmpFolder.listFiles(new OnlyDirs()); if (foldersInTmpFolder.length != 1) { throw new IOException(tr("Zip doesn't contain a library")); } sourceFile = foldersInTmpFolder[0]; } catch (IOException e) { activeEditor.statusError(e); return; } } File libFolder = sourceFile; if (FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), libFolder)) { activeEditor.statusError(tr("A subfolder of your sketchbook is not a valid library")); return; } if (FileUtils.isSubDirectory(libFolder, new File(PreferencesData.get("sketchbook.path")))) { activeEditor.statusError(tr("You can't import a folder that contains your sketchbook")); return; } String libName = libFolder.getName(); if (!BaseNoGui.isSanitaryName(libName)) { String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n" + "Library names must contain only basic letters and numbers.\n" + "(ASCII only and no spaces, and it cannot start with a number)"), libName); activeEditor.statusError(mess); return; } String[] headers; File libProp = new File(libFolder, "library.properties"); File srcFolder = new File(libFolder, "src"); if (libProp.exists() && srcFolder.isDirectory()) { headers = BaseNoGui.headerListFromIncludePath(srcFolder); } else { headers = BaseNoGui.headerListFromIncludePath(libFolder); } if (headers.length == 0) { activeEditor.statusError(tr("Specified folder/zip file does not contain a valid library")); return; } // copy folder File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName()); if (!destinationFolder.mkdir()) { activeEditor .statusError(I18n.format(tr("A library named {0} already exists"), sourceFile.getName())); return; } try { FileUtils.copy(sourceFile, destinationFolder); } catch (IOException e) { activeEditor.statusError(e); return; } activeEditor.statusNotice(tr("Library added to your libraries. Check \"Include library\" menu")); } catch (IOException e) { // FIXME error when importing. ignoring :( } finally { // delete zip created temp folder, if exists newLibraryImported = true; FileUtils.recursiveDelete(tmpFolder); } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void dcm2JPEG(int thumbnailSize) { /**//from www.ja v a2 s . c o m * Why couldn't? It works! if (System.getProperty("os.name").toUpperCase().indexOf("MAC OS") != -1) { JOptionPane.showMessageDialog(this, "Operation Not Available to MAC OS.", "Missing JAI Tool", JOptionPane.WARNING_MESSAGE); return; } */ String pathDir = "."; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pathDir)); chooser.setDialogTitle("Dicoogle Dcm2JPG - Select DICOM File"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //chooser.setFileFilter(arg0) chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File filePath = new File(chooser.getSelectedFile().toString()); if (filePath.exists() && filePath.isFile() && filePath.canRead()) { File jpgFile = new File(filePath.getAbsolutePath() + ".jpg"); Dicom2JPEG.convertDicom2Jpeg(filePath, jpgFile, thumbnailSize); } } }
From source file:qrcode.JavaQR.java
@Override public void run() { setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); JPanel centerPanel = new JPanel(); JPanel bottomPanel = new JPanel(); topPanel.setLayout(new GridLayout(0, 1)); topPanel.setBorder(BorderFactory.createTitledBorder("Input Data")); JPanel rowTopPanel = new JPanel(); rowTopPanel.setLayout(new GridLayout(0, 2)); JLabel accKey = new JLabel("Access Key"); JTextField accField = new JTextField(5); accField.setEditable(false);//w w w .j ava2 s . c o m accField.setText(Data.accessKey); JLabel regNo = new JLabel("Registration Number"); JTextField regField = new JTextField(5); regField.setEditable(false); regField.setText(Data.registrationNumber); JLabel licNo = new JLabel("License Number"); JFormattedTextField licField = new JFormattedTextField(); licField.setEditable(false); licField.setText(Data.licenseNumber); rowTopPanel.add(accKey); rowTopPanel.add(accField); rowTopPanel.add(regNo); rowTopPanel.add(regField); rowTopPanel.add(licNo); rowTopPanel.add(licField); topPanel.add(rowTopPanel); centerPanel.setLayout(new GridLayout(0, 1)); centerPanel.setBorder(BorderFactory.createTitledBorder("QR Code")); JPanel rowCenPanel = new JPanel(); rowCenPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton genBtn = new JButton("Download QR Code"); JButton homeBtn = new JButton("Back to Start"); String accessKey = accField.getText().toString(); String regKey = regField.getText().toString(); String licKey = licField.getText().toString(); JSONObject jsonObject = new JSONObject(); try { jsonObject.put("accessKey", accessKey); jsonObject.put("registrationNumber", regKey); jsonObject.put("licenseNumber", licKey); } catch (JSONException e1) { e1.printStackTrace(); } QRLogic qrGen = new QRLogic(); BufferedImage image = qrGen.generateQR(jsonObject); centerPanel.add(new JLabel(new ImageIcon(image))); bottomPanel.setLayout(new GridLayout(2, 1)); rowCenPanel.add(homeBtn); rowCenPanel.add(genBtn); bottomPanel.add(rowCenPanel); add(topPanel, BorderLayout.NORTH); add(bottomPanel, BorderLayout.SOUTH); add(centerPanel, BorderLayout.CENTER); Data.mainFrame.setSize(1000, 500); genBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Date date = new Date(); String newDate = new SimpleDateFormat("yyyy-MM-dd h-m-a").format(date); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); File myFile = new File(Data.registrationNumber + ".png"); fileChooser.setSelectedFile(myFile); fileChooser.showSaveDialog(null); String dlDir = fileChooser.getSelectedFile().getPath(); System.out.println(dlDir); String fileName = fileChooser.getSelectedFile().getName(); String filePath = ""; if (fileName != null) { filePath = dlDir + ".png"; } else { filePath = dlDir + "/" + Data.registrationNumber + ".png"; } String fileType = "png"; myFile = new File(filePath); if (dlDir != null) { try { ImageIO.write(image, fileType, myFile); JOptionPane.showMessageDialog(Data.mainFrame, "QR Code Saved in " + dlDir); } catch (IOException e1) { e1.printStackTrace(); } } } }); homeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("inventory"); } }); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } }
From source file:ro.nextreports.designer.wizimport.ImportPathSelectionWizardPanel.java
private void init() { setLayout(new BorderLayout()); nameTextField = new JTextField(); nameTextField.setPreferredSize(dim); nameTextField.setEditable(false);/* ww w . ja v a 2s . co m*/ propCheck = new JCheckBox(I18NSupport.getString("wizard.import.panel.start.select.title.prop"), true); selButton = new JButton(); selButton.setPreferredSize(buttonDim); selButton.setMaximumSize(buttonDim); selButton.setMinimumSize(buttonDim); selButton.setIcon(ImageUtil.getImageIcon("folder")); selButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(I18NSupport.getString("import.long.desc")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog((JDialog) context.getAttribute(ImportWizard.MAIN_FRAME)); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f != null) { nameTextField.setText(f.getName()); path = f.getAbsolutePath(); } } } }); JPanel dsPanel = new JPanel(new GridBagLayout()); dsPanel.add(new JLabel(I18NSupport.getString("wizard.import.panel.start.select.title.label")), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); dsPanel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); dsPanel.add(selButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); dsPanel.add(propCheck, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); dsPanel.add(new JLabel(""), new GridBagConstraints(3, 1, 1, 2, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); add(dsPanel, BorderLayout.CENTER); }
From source file:ropes.MainWindow.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed //TODO display loader animation while liberys are loading DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setMultiSelectionEnabled(true);/* w w w. j av a2s. c o m*/ int returnVal = fc.showOpenDialog(MainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); for (File file : files) { if (file.isFile()) { addFileToList(file); } else if (file.isDirectory()) { //adds the parent to tree root.add(new DefaultMutableTreeNode(file)); //adds all the subfolders and files to the parent addFileRecursive(file.toString()); } } } }
From source file:ropes.MainWindow.java
private void jButton_changePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_changePathActionPerformed final JFileChooser fc = new JFileChooser(getSelectedPathFromCMB()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(MainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); Path p = Paths.get(file.toString()); //if root is changed via the change path botton, then also change to the right media in the combobox if (!p.getRoot().toString().equals(getSelectedPathFromCMB())) { for (int i = 0; i < jComboBox_media.getItemCount(); i++) { if (jComboBox_media.getItemAt(i).toString().contains(p.getRoot().toString())) { jComboBox_media.setSelectedIndex(i); break; }/* w ww. j ava 2 s. c om*/ } } jLabel_path.setText(file.toString()); } }
From source file:smlm.util.SRutil.java
public static String[][] getFiles(String title, String initialRoot, String initialFile) { if (title == null || title == "") title = "Choose files"; if (initialRoot == null || initialRoot == "") initialRoot = "E:\\Data"; JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); FileNameExtensionFilter filter = new FileNameExtensionFilter("Tiff files", "tif", "tiff"); chooser.setFileFilter(filter);/*from w w w . j ava2s . co m*/ chooser.setDialogTitle(title); chooser.setCurrentDirectory(new File(initialRoot)); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String[][] files = new String[chooser.getSelectedFiles().length][2]; for (int i = 0; i < files.length; i++) { files[i][0] = chooser.getSelectedFiles()[i].getParent(); files[i][1] = chooser.getSelectedFiles()[i].getName(); } return files; } else return null; }
From source file:sms.ViewResults.java
private void itextPrint() { // String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'" // + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'"; methods nn = new methods(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {/*from w w w .j a v a 2 s. c o m*/ Form1Exams n = new Form1Exams(); Document pdfp = new Document(); PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf"))); pdfp.open(); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD)); Paragraph po = new Paragraph(); po.setAlignment(Element.ALIGN_CENTER); po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); Paragraph pd = new Paragraph(); pd.setAlignment(Element.ALIGN_CENTER); pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 14, Font.BOLD)); p.add("ITHANGA SECONDARY SCHOOL"); po.add("PO.BOX 238 ITHANGA THIKA"); pd.add(new Date().toString()); pdfp.add(p); pdfp.add(po); pdfp.add(pd); pdfp.add(new Paragraph("\n.................................................................." + ".................................................................................\n")); String[] names = n.findSubjectname(); PdfPTable tbl = new PdfPTable(names.length + 6); tbl.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); PdfPTable tbl1 = new PdfPTable(names.length + 6); tbl1.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); PdfPCell cell = new PdfPCell(new Paragraph("RESULTS")); cell.setColspan((names.length + 4) * 2); cell.setBackgroundColor(Color.CYAN); tbl1.addCell(cell); tbl1.addCell("Pos"); tbl1.addCell("id"); tbl1.addCell("Name"); int a; for (a = 0; a < names.length; a++) { String s = names[a]; tbl1.addCell(s.substring(0, Math.min(s.length(), 3))); } tbl1.addCell("Tot"); tbl1.addCell("Ave"); tbl1.addCell("Agg"); pdfp.add(tbl1); try { String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); int subjectCount = Subjects.length; ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText()); for (int i = 0; i < users.size(); i++) { tbl.addCell(String.valueOf(i + 1)); String id = ((ExamDbDataHolder) users.get(i)).getSid(); String nam = nn.getStudentName(id); String name = "Eric"; tbl.addCell(id); tbl.addCell(nam); int c = 2; for (int s = 0; s < Subjects.length; s++) { if (Subjects[s].equals("s1")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); c++; } else if (Subjects[s].equals("s2")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); c++; } else if (Subjects[s].equals("s3")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); c++; } else if (Subjects[s].equals("s4")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); c++; } else if (Subjects[s].equals("s5")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); c++; } else if (Subjects[s].equals("s6")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); c++; } else if (Subjects[s].equals("s7")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); c++; } else if (Subjects[s].equals("s8")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); c++; } else if (Subjects[s].equals("s9")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); c++; } else if (Subjects[s].equals("s10")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); c++; } else if (Subjects[s].equals("s11")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); c++; } else if (Subjects[s].equals("s12")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); c++; } else if (Subjects[s].equals("s13")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); c++; } else if (Subjects[s].equals("s14")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); c++; } else if (Subjects[s].equals("s15")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); c++; } else if (Subjects[s].equals("s16")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); c++; } else if (Subjects[s].equals("s17")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); c++; } else if (Subjects[s].equals("s18")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); c++; } else if (Subjects[s].equals("s19")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); c++; } else if (Subjects[s].equals("s20")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); c++; } else if (Subjects[s].equals("s21")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); c++; } else if (Subjects[s].equals("s22")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); c++; } else if (Subjects[s].equals("s23")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); c++; } } int tt = ((ExamDbDataHolder) users.get(i)).getTotal(); tbl.addCell(String.valueOf(tt)); float g = Float.valueOf(tt) / 11; tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g)); tbl.addCell(gr); } pdfp.add(tbl); } catch (Exception j) { j.printStackTrace(); } pdfp.close(); // Image img=new Image.getInstance("j.png"); } catch (DocumentException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:storybook.export.DlgExport.java
private void btFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFolderActionPerformed JFileChooser chooser = new JFileChooser(txFolder.getText()); chooser.setFileSelectionMode(1); int i = chooser.showOpenDialog(this); if (i != 0)/*from w ww.j av a 2 s .c om*/ return; File file = chooser.getSelectedFile(); txFolder.setText(file.getAbsolutePath()); }
From source file:tax.MainForm.java
private void printMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printMonthActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String folderName = chooser.getSelectedFile().getAbsolutePath(); // System.out.println(folderName); try {/*from ww w. ja va2 s . c o m*/ FileUtils.forceMkdir(new File(folderName + "/" + curYear + "/pdf")); Printer.createPdf( folderName + "/" + curYear + "/pdf/" + curMonth + ". " + Util.months[curMonth - 1] + ".pdf", curTable); } catch (IOException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } new Completed("<html> ? ?<br> .</html>") .setVisible(true); } }