Example usage for javax.swing JFileChooser setLocale

List of usage examples for javax.swing JFileChooser setLocale

Introduction

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

Prototype

public void setLocale(Locale l) 

Source Link

Document

Sets the locale of this component.

Usage

From source file:cn.pholance.datamanager.common.components.JRViewer.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();/* ww w. j  av  a2  s.c o m*/
    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter(saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter(saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(this.jasperReportsContext, getLocale(),
                        this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled()) {
                log.error("Save error.", e);
            }
            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:neg.JRViewerFactura.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();//w w  w . j  a  v a2  s .  c  om
    String archivo = "Pepe.txt";
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = (JRSaveContributor) saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled())
                log.error("Save error.", e);

            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:neg.JRViewerFactura.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt, String nombre) {
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();/*from   ww  w  . ja v a 2s  .co m*/
    String archivo = nombre;
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0));
    }

    if (lastFolder != null) {
        //fileChooser.setCurrentDirectory(lastFolder);
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = (JRSaveContributor) saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled())
                log.error("Save error.", e);

            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:app.RunApp.java

/**
 * Action of Choose file button on Principal tab
 * /*from  w  ww  . j a v a  2s  .co m*/
 * @param evt Event
 */
private void buttonChooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFileActionPerformed
    final JFileChooser jfile1 = new JFileChooser();
    jfile1.setLocale(Locale.UK);
    jfile1.repaint();
    FileNameExtensionFilter fname = new FileNameExtensionFilter(".arff", "arff");
    jfile1.setFileFilter(fname);

    final boolean deleteXML = false;

    final int returnVal = jfile1.showOpenDialog(this);

    progressBar.setIndeterminate(true);
    progressFrame.setVisible(true);
    progressFrame.repaint();

    new Thread(new Runnable() {
        @Override
        public void run() {
            // do the long-running work here
            loadDataset(returnVal, jfile1, deleteXML);
            // at the end:
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    progressBar.setIndeterminate(false);
                    progressFrame.setVisible(false);
                    progressFrame.repaint();
                }//run
            }); //invokeLater
        }
    }).start();
}