Example usage for javax.swing JFileChooser JFileChooser

List of usage examples for javax.swing JFileChooser JFileChooser

Introduction

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

Prototype

public JFileChooser() 

Source Link

Document

Constructs a JFileChooser pointing to the user's default directory.

Usage

From source file:AccessoryFileChooser.java

public AccessoryFileChooser() {
    super("Accessory Test Frame");
    setSize(350, 200);/*from   w  ww  .  java  2s.c om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton accButton = new JButton("Accessory");
    statusbar = new JLabel("Output of your selection will go here");
    chooser = new JFileChooser();
    AudioAccessory aa = new AudioAccessory();
    chooser.setAccessory(aa);
    chooser.addPropertyChangeListener(aa); // to receive selection changes
    chooser.addActionListener(aa); // to receive approve/cancel button
    // events

    accButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int option = chooser.showOpenDialog(AccessoryFileChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose "
                        + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName()
                                : "nothing"));
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });
    c.add(accButton);
    c.add(statusbar);
}

From source file:MyViewChooser.java

public MyViewChooser() {
    super("File View Test Frame");
    setSize(350, 200);//www . j  a va 2 s . c o  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();

            // Ok, set up our own file view for the chooser
            chooser.setFileView(new ThumbNailFileView(MyViewChooser.this));

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
}

From source file:WeatherFrame.java

public WeatherFrame() {
    initComponents();/*w w w  . ja va 2  s. c  om*/

    fc = new JFileChooser();
    fc.setMultiSelectionEnabled(true);

    //only can select a single button a time
    ButtonGroup group = new ButtonGroup();
    group.add(AllRadioButton);
    group.add(YearlyRadioButton);
    group.add(MonthlyRadioButton);
    group.add(WeeklyRadioButton);
    group.add(DailyRadioButton);

    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Temperature", "Humidity",
            "Barometric Pressure", "Windspeed", "UVindex", "Raindfall" }));

    TempSet = new TimeSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart("Temperature", "", "Degree Fahrenheit", TempSet,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    ChartPanel.setLayout(new java.awt.BorderLayout());
    ChartPanel CP = new ChartPanel(chart);
    CP.setPreferredSize(new Dimension(ChartPanel.getWidth(), ChartPanel.getHeight()));
    ChartPanel.add(CP, BorderLayout.CENTER);

    DefaultValueDataset dataset = new DefaultValueDataset(20f);
    ThermometerPlot thermometerplot = new ThermometerPlot(dataset);
    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true);
    jfreechart.setBackgroundPaint(new Color(240, 240, 240));
    thermometerplot.setThermometerPaint(Color.lightGray);
    thermometerplot.setThermometerStroke(new BasicStroke(2.0F));
    ChartPanel DP = new ChartPanel(jfreechart);
    DP.setPreferredSize(new Dimension(TempThermoPanel.getWidth(), TempThermoPanel.getHeight()));
    TempThermoPanel.setLayout(new java.awt.BorderLayout());
    TempThermoPanel.add(DP);
    TempThermoPanel.validate();
}

From source file:com.codecrate.shard.ui.form.BioForm.java

protected JComponent createFormControl() {
    SwingBindingFactory bindingFactory = (SwingBindingFactory) getBindingFactory();

    JFileChooser fileChooser = new JFileChooser();
    DefaultFileFilter filter = new DefaultFileFilter();
    filter.addExtension("jpg");
    filter.addExtension("gif");
    filter.addExtension("png");

    fileChooser.setFileFilter(filter);//w w w .  ja  va  2s .c o m

    TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
    formBuilder.add("bio.name");
    formBuilder.row();
    formBuilder.add(new JFileChooserBinding(getFormModel(), "bio.portraitFile", fileChooser));
    formBuilder.row();
    formBuilder.add("bio.height");
    formBuilder.row();
    formBuilder.add("bio.weight");
    formBuilder.row();
    formBuilder.addInScrollPane(bindingFactory.createBoundTextArea("bio.backstory", 5, 0));
    return formBuilder.getForm();
}

From source file:com.zestedesavoir.zestwriter.utils.Configuration.java

private static String getDefaultWorkspace() {
    JFileChooser fr = new JFileChooser();
    FileSystemView fw = fr.getFileSystemView();
    return fw.getDefaultDirectory().getAbsolutePath() + File.separator + "zwriter-workspace";
}

From source file:ihm.mainActivity.java

/**
 * Creates new form testBuild/*from  ww w.  ja v  a 2 s . c o  m*/
 */
public mainActivity() {
    dataList = new DataList();
    dataList.addObserver(this);
    chart = ChartFactory.createXYLineChart("Graphique", "x", "Value", createDataset(), PlotOrientation.VERTICAL,
            true, true, false);
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV Files", "csv");
    fileChooser.setFileFilter(filter);
    initComponents();
}

From source file:com.moneydance.modules.features.importlist.io.DefaultDirectoryChooser.java

@Override
void chooseBaseDirectory() {
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(this.getLocalizable().getDirectoryChooserTitle());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // disable the "All files" option.
    fileChooser.setAcceptAllFileFilterUsed(false);

    try {/*from   w w w.j a va2  s  .co  m*/
        fileChooser.setCurrentDirectory(FileUtils.getUserDirectory());
    } catch (SecurityException e) {
        LOG.log(Level.WARNING, e.getMessage(), e);
    }

    if (this.getBaseDirectory() != null) {
        final File parentDirectory = this.getBaseDirectory().getParentFile();
        fileChooser.setCurrentDirectory(parentDirectory);
    }

    if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
        return;
    }

    this.getPrefs().setBaseDirectory(fileChooser.getSelectedFile().getAbsolutePath());

    LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory()));
}

From source file:rework.MainFrame.java

/**
 * Creates new form MainFrame//from w  w w .ja  v  a2 s  . co m
 */
public MainFrame() {
    chart = ChartFactory.createXYLineChart("Graphique", "x", "Value", createDataset(), PlotOrientation.VERTICAL,
            true, true, false);

    initComponents();

    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV Files", "csv");
    fileChooser.setFileFilter(filter);

    layerStack1.initComponents(transfList);
    layerStack1.updateLayerStack();

    datalist.addObserver(this);
    transfList.addObserver(layerStack1);

    datalist.add(new Point(new Date(), 1, 5.0));
    datalist.add(new Point(new Date(), 2, 15.0));
    datalist.add(new Point(new Date(), 3, 25.0));
    datalist.add(new Point(new Date(), 4, 20.0));
    datalist.add(new Point(new Date(), 5, 25.0));
    datalist.add(new Point(new Date(), 6, 35.0));
    datalist.add(new Point(new Date(), 7, 5.0));
    datalist.add(new Point(new Date(), 8, 15.0));
    datalist.add(new Point(new Date(), 9, 25.0));
    datalist.add(new Point(new Date(), 10, 20.0));
    datalist.add(new Point(new Date(), 11, 25.0));
    datalist.add(new Point(new Date(), 12, 35.0));
    datalist.add(new Point(new Date(), 13, 5.0));
    datalist.add(new Point(new Date(), 14, 15.0));
    datalist.add(new Point(new Date(), 15, 25.0));
    datalist.add(new Point(new Date(), 16, 20.0));
    datalist.add(new Point(new Date(), 17, 25.0));
    datalist.add(new Point(new Date(), 18, 35.0));

    tabStack.revalidate();

}

From source file:lince.controladores.exportar.AbrirExportarHoisan.java

@Override
public void execute() {
    if (fc == null) {
        fc = new JFileChooser();
        //Add a custom file filter and disable the default
        fc.addChoosableFileFilter(new FiltroArchivos("mdb", ResourceBundleHelper.getI18NLabel("HOISAN")));
        fc.setAcceptAllFileFilterUsed(false);
    }/*from w  w  w  . jav  a2  s . c om*/
    //Show it.
    int returnVal = fc.showDialog(LinceFrame.getInstance(),
            ResourceBundleHelper.getI18NLabel("actions.export.Hoisan.confirm"));
    //Process the results.
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        log.warn("Init export to Hoisan file: " + file.getName() + ".");
        HoisanTool hoisan = new HoisanTool();
        String result = hoisan.exportFile(file);
        String message = ResourceBundleHelper.getI18NLabel(
                StringUtils.isEmpty(result) ? "action.result.export.ok" : "action.result.export.fail");
        if (StringUtils.isNotEmpty(result)) {
            message = message + "\n" + result;
        }
        JOptionPane.showMessageDialog(LinceFrame.getInstance(), message);
    } else {
        log.warn("Hoisan export cancelled by user.");
    }
    //Reset the file chooser for the next time it's shown.
    fc.setSelectedFile(null);
}

From source file:com.itd.dbmrgdao.TestTime4.java

@Ignore
@org.junit.Test/*  ww  w  .j  av a2  s  .co 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;

        StringBuilder mySql = new StringBuilder(
                "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p1end,p2start,p2end,otstart,otend) VALUES (?,?,?,?,?,?,?,?,?)");

        while ((strLine = br.readLine()) != null) {
            String[] parts = strLine.split(" ");

            if (sysid != null && !sysid.equals(parts[0])) {
                mySql = mySql.append(", (").append(sysid).append(",\"1985\"").append(",").append(scdate)
                        .append(",").append(p1Start).append(",").append(p1End).append(",").append(p2Start)
                        .append(",").append(p2End).append(",").append(otStart).append(",").append(otEnd)
                        .append(")");

                //                    if (p1Start != null || p2End != null) {
                //                        ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
                //                        p1Start = scanRule.getP1start();
                //                        p2End = scanRule.getP2end();
                //                    }
                //                    ScanDataTest scanData = new ScanDataTest(sysid, scdate, p1Start, p2End);

                p1Start = null;
                p2End = null;

            }

            sysid = parts[0];
            scdate = parts[1];

            if (parts[6].equals("01")) {
                p1Start = CompareTime(p1Start, parts[5], "01");
            } else {
                p2End = CompareTime(p2End, parts[5], "04");
            }

        }

        //last line
        //            if (p1Start != null || p2End != null) {
        //                ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
        //                p1Start = scanRule.getP1start();
        //                p2End = scanRule.getP2end();
        //            }
        //            ScanDataTest scanData = new ScanDataTest(sysid, scdate, p1Start, p2End);
        //            System.out.println(scanData);
        br.close();

    } catch (Exception e) {

        JOptionPane.showMessageDialog(null, e);

    }

}