Example usage for javax.swing JFileChooser setCurrentDirectory

List of usage examples for javax.swing JFileChooser setCurrentDirectory

Introduction

In this page you can find the example usage for javax.swing JFileChooser setCurrentDirectory.

Prototype

@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.")
public void setCurrentDirectory(File dir) 

Source Link

Document

Sets the current directory.

Usage

From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java

protected void saveParser() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(AllPluginables.USER_LOG_IMPORTERS);
    chooser.addChoosableFileFilter(new FileFilter() {

        @Override/*from w  w  w  .j  av a 2 s.co m*/
        public String getDescription() {
            return "*.pattern files";
        }

        @Override
        public boolean accept(File f) {
            return f.getName().endsWith(".pattern") || f.isDirectory();
        }
    });
    int showSaveDialog = chooser.showSaveDialog(this);
    if (showSaveDialog == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        if (!selectedFile.getName().endsWith(".pattern")) {
            selectedFile = new File(selectedFile.getAbsolutePath() + ".pattern");
        }
        if (selectedFile.exists() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this,
                "Do you want to overwrite file " + selectedFile.getName() + "?", "Save parser",
                JOptionPane.YES_NO_OPTION)) {
            return;
        }
        String text = propertyEditor.getText();
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(selectedFile);
            IOUtils.write(text, output);
            LogImporterUsingParser log4jImporter = createLog4jImporter(text);
            otrosApplication.getAllPluginables().getLogImportersContainer().addElement(log4jImporter);
        } catch (Exception e) {
            LOGGER.severe("Can't save parser: " + e.getMessage());
            JOptionPane.showMessageDialog(this, "Can't save parser: " + e.getMessage(), "Error saving parser",
                    JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(output);
        }
    }
}

From source file:plugin.notes.gui.NotesView.java

/**
 *  {@literal handle File->Open.} Will open any .gmn files, and import them into your
 *  notes structure//from  w w w  .  ja  v a  2 s . com
 */
public void handleOpen() {
    // TODO fix
    String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, System.getProperty("user.dir"));
    File defaultFile = new File(sFile);
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(defaultFile);
    chooser.addChoosableFileFilter(getFileType());
    chooser.setFileFilter(getFileType());
    chooser.setMultiSelectionEnabled(true);
    Component component = GMGenSystem.inst;
    Cursor originalCursor = component.getCursor();
    component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    int option = chooser.showOpenDialog(GMGenSystem.inst);

    if (option == JFileChooser.APPROVE_OPTION) {
        for (File noteFile : chooser.getSelectedFiles()) {
            SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, noteFile.toString());

            if (noteFile.toString().endsWith(EXTENSION)) {
                openGMN(noteFile);
            }
        }
    }

    GMGenSystem.inst.setCursor(originalCursor);
    refreshTree();
}

From source file:plugin.notes.gui.NotesView.java

/**
 *  obtains an Image for input using a custom JFileChooser dialog
 *
 *@param  startDir  Directory to open JFielChooser to
 *@param  exts      Extensions to search for
 *@param  desc      Description for files
 *@return           File pointing to the selected image
 *///from   w ww.  ja  v  a  2 s  .  c om
private File getImageFromChooser(String startDir, String[] exts, String desc) {
    JFileChooser jImageDialog = new JFileChooser();
    jImageDialog.setCurrentDirectory(new File(startDir));
    jImageDialog.setAccessory(new ImageFileChooserPreview(jImageDialog));
    jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
    jImageDialog.setFileFilter(new FileNameExtensionFilter(desc, exts));
    jImageDialog.setDialogTitle("Select an Image to Insert");

    int optionSelected = jImageDialog.showDialog(this, "Insert");

    if (optionSelected == JFileChooser.APPROVE_OPTION) {
        return jImageDialog.getSelectedFile();
    }

    return null;
}

From source file:PolyGlot.IOHandler.java

/**
 * Queries user for image file, and returns it
 * @param parent the parent window from which this is called
 * @return the image chosen by the user, null if canceled
 * @throws IOException If the image cannot be opened for some reason
 *//*from   w  w  w .  j av a2 s .  c o  m*/
public static BufferedImage openImageFile(Component parent) throws IOException {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Open Images");
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "gif", "jpg", "jpeg", "bmp",
            "png", "wbmp");
    chooser.setFileFilter(filter);
    String fileName;
    chooser.setCurrentDirectory(new File("."));

    if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        fileName = chooser.getSelectedFile().getAbsolutePath();
    } else {
        return null;
    }

    return getImage(fileName);
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void dcm2JPEG(int thumbnailSize) {

    /**//from   w w w  . ja va  2s . c  om
     * 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:ru.gelin.fictionbook.reader.actions.OpenAction.java

/**
 *  Shows file chosing dialog and returns choosed file or null if
 *  file was not selected./*from w w w. j a v  a2 s .  c om*/
 */
File chooseFile() {
    File result = null;
    JFileChooser chooser = new JFileChooser();
    if (currentDirectory != null) {
        chooser.setCurrentDirectory(currentDirectory);
    }
    chooser.addChoosableFileFilter(new FBFileFilter());
    int returnValue = chooser.showOpenDialog(getParentComponent());
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        result = chooser.getSelectedFile();
        if (log.isInfoEnabled()) {
            log.info(result + " file is selected");
        }
    }
    currentDirectory = chooser.getCurrentDirectory(); //save current dialog directory
    return result;
}

From source file:scrabble.frmStartup.java

private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileActionPerformed

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    fileChooser.setFileFilter(new FileNameExtensionFilter("Archivos XML", "xml", "xml"));
    int result = fileChooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        txtFilePath.setText(selectedFile.getAbsolutePath());

    }/*from w  ww .  j  av a2  s .co m*/

}

From source file:sd_mensajeria.GUI.Registro.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    int result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        //System.out.println("Selected file: " + selectedFile.getAbsolutePath());
        txtFoto.setText(selectedFile.getAbsolutePath());
    }//from   w w w .  j a  v a2 s. c o  m

}

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  a va2  s.c o  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 {/*  w  ww. j a  v  a2 s. co  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);
        }
    }

}