Example usage for javax.swing JFileChooser FILES_ONLY

List of usage examples for javax.swing JFileChooser FILES_ONLY

Introduction

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

Prototype

int FILES_ONLY

To view the source code for javax.swing JFileChooser FILES_ONLY.

Click Source Link

Document

Instruction to display only files.

Usage

From source file:com.philips.cn.hr.pps.App.java

private void uploadBtn1ActionPerformed(java.awt.event.ActionEvent evt) {
    File file = chooseFile(filter, JFileChooser.FILES_ONLY);
    if (file != null) {
        this.filePath1.setText(file.getAbsolutePath());
    }/*from  w  w  w. j a  va 2 s.c  o m*/
}

From source file:view.MainFrame.java

private void menuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemOpenActionPerformed
    // TODO add your handling code here:
    JFileChooser filech = new JFileChooser();
    filech.setFileSelectionMode(JFileChooser.FILES_ONLY);
    filech.setFileFilter(new FileNameExtensionFilter("WAV Files", "wav"));
    int ret = filech.showOpenDialog(this);

    if (ret == JFileChooser.APPROVE_OPTION) {
        try {/*from  w ww .  j  a v a 2s.c o  m*/
            wavFile = WavFile.openWavFile(filech.getSelectedFile());
            textArea.append(wavFile.getInfoString());
            samples = new double[wavFile.getNumChannels() * (int) wavFile.getSampleRate()];
            int nFrames = wavFile.readFrames(samples, (int) wavFile.getSampleRate());
            textArea.append(nFrames + " frames lidos.\n");

            double valuesX[] = new double[samples.length];
            for (int i = 0; i < samples.length; i++) {
                valuesX[i] = i;
            }

            showChart(wavFile.getNumChannels() * (int) wavFile.getSampleRate(), samples, valuesX, "Amostra",
                    "Amplitude", "Amplitude das Amostras do ?udio", "Audio");
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (WavFileException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.philips.cn.hr.pps.App.java

private void uploadBtn2ActionPerformed(java.awt.event.ActionEvent evt) {
    File file = chooseFile(filter, JFileChooser.FILES_ONLY);
    if (file != null) {
        this.filePath2.setText(file.getAbsolutePath());
    }/*from   w w  w  .ja va2 s  .c o m*/
}

From source file:de.xplib.xdbm.ui.dialog.FirstStartSetup.java

/**
 * // www.j a  v a  2  s .c o  m
 */
private void initUI() {

    this.getContentPane().setLayout(this.mainLayout);

    Locale l = this.config.getLocale();
    Object[] args = new Object[0];

    this.jfField.addFileFilter(JFileField.JAR_FILE_FILTER);
    this.jfField.setFileSelectionMode(JFileChooser.FILES_ONLY);
    this.jfField.addSelectListener(new FileSelectListener());
    this.jfField.addDocumentListener(new EnableButtonListener());
    this.jfField.setToolTipText(MessageManager.getText("setup.dialog.jarfile.tooltip", "text", args, l));

    this.jtfClass.getDocument().addDocumentListener(new EnableButtonListener());
    this.jtfClass.setToolTipText(MessageManager.getText("setup.dialog.class.tooltip", "text", args, l));

    this.jtfDbURI.setToolTipText(MessageManager.getText("setup.dialog.dburi.tooltip", "text", args, l));

    this.jbTest.setEnabled(false);
    this.jbTest.setText(MessageManager.getText("setup.dialog.test.label", "text", args, l));
    this.jbTest.setToolTipText(MessageManager.getText("setup.dialog.test.tooltip", "text", args, l));
    this.jbTest.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            if (actionPerformedTest(ae)) {
                JOptionPane.showMessageDialog(FirstStartSetup.this,
                        MessageManager.getText("setup.dialog.test.success.message", "text", new Object[0],
                                config.getLocale()),
                        MessageManager.getText("setup.dialog.test.success.title", "text", new Object[0],
                                config.getLocale()),
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });

    this.jbCancel.setText(MessageManager.getText("setup.dialog.cancel.label", "text", args, l));
    this.jbCancel.setToolTipText(MessageManager.getText("setup.dialog.cancel.tooltip", "text", args, l));
    this.jbCancel.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            System.exit(0);
        }
    });

    this.jbOk.setEnabled(false);
    this.jbOk.setText(MessageManager.getText("setup.dialog.ok.label", "text", args, l));
    this.jbOk.setToolTipText(MessageManager.getText("setup.dialog.ok.tooltip", "text", args, l));
    this.jbOk.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            if (actionPerformedTest(ae)) {

                String jar = jfField.getText().trim();

                config.putDriver(jar, jtfClass.getText().trim());

                String uri = jtfDbURI.getText().trim();
                if (!uri.equals("")) {
                    config.putDatabaseURI(jar, uri);
                }

                dispose();
            }
        }
    });

    FormLayout layout = new FormLayout("right:pref, 3dlu, pref, 3dlu, pref, 3dlu, pref",
            "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p");

    layout.setColumnGroups(new int[][] { { 3, 5, 7 } });

    PanelBuilder builder = new PanelBuilder(layout);
    builder.setDefaultDialogBorder();

    //      Obtain a reusable constraints object to place components in the grid.
    CellConstraints cc = new CellConstraints();

    //         Fill the grid with components; the builder can create
    //         frequently used components, e.g. separators and labels.

    //         Add a titled separator to cell (1, 1) that spans 7 columns.
    builder.addSeparator(MessageManager.getText("setup.dialog.header", "text", args, l), cc.xyw(1, 1, 7));
    builder.addLabel(MessageManager.getText("setup.dialog.jarfile.label", "text", args, l), cc.xy(1, 3));
    builder.add(this.jfField, cc.xyw(3, 3, 5));
    builder.addLabel(MessageManager.getText("setup.dialog.class.label", "text", args, l), cc.xy(1, 5));
    builder.add(this.jtfClass, cc.xyw(3, 5, 5));
    builder.addLabel(MessageManager.getText("setup.dialog.dburi.label", "text", args, l), cc.xy(1, 7));
    builder.add(this.jtfDbURI, cc.xyw(3, 7, 5));

    builder.addSeparator("", cc.xyw(1, 9, 7));

    builder.add(this.jbTest, cc.xy(3, 11));
    builder.add(this.jbCancel, cc.xy(5, 11));
    builder.add(this.jbOk, cc.xy(7, 11));

    this.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);

    this.statusPanel.setLayout(this.statusLayout);
    this.statusPanel.add(this.statusLabel);
    this.statusPanel.add(this.statusBar);

    this.statusLabel.setBorder(BorderFactory.createLoweredBevelBorder());

    this.statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
    this.statusBar.setStringPainted(true);

    this.getContentPane().add(this.statusPanel, BorderLayout.SOUTH);
}

From source file:io.github.jeremgamer.editor.panels.IconFrame.java

public IconFrame(JFrame parent) {
    this.setModal(true);
    this.setResizable(false);
    ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>();
    try {//  ww  w.  j a v  a2s. com
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    this.setIconImages((List<? extends Image>) icons);
    this.setTitle("Icnes");

    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.LINE_AXIS));
    content.setBorder(BorderFactory.createTitledBorder(""));

    try {
        remove128.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove64.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove32.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        remove16.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    browse128.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "128.png");
                try {
                    x128.repaint();
                    x128.getGraphics().drawImage(ImageIO.read(new File(path)), 0 + 10, 0 + 20, 128, 128, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove128.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/128.png");
            file.delete();
            x128.repaint();
        }
    });
    browse64.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "64.png");
                try {
                    x64.repaint();
                    x64.getGraphics().drawImage(ImageIO.read(new File(path)), 32 + 10, 32 + 20, 64, 64, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove64.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/64.png");
            file.delete();
            x64.repaint();
        }
    });
    browse32.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "32.png");
                try {
                    x32.repaint();
                    x32.getGraphics().drawImage(ImageIO.read(new File(path)), 48 + 10, 48 + 20, 32, 32, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove32.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/32.png");
            file.delete();
            x32.repaint();
        }
    });
    browse16.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "16.png");
                try {
                    x16.repaint();
                    x16.getGraphics().drawImage(ImageIO.read(new File(path)), 56 + 10, 56 + 20, 16, 16, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    remove16.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File("projects/" + Editor.getProjectName() + "/16.png");
            file.delete();
            x16.repaint();
        }
    });

    content.add(x128);
    content.add(x64);
    content.add(x32);
    content.add(x16);
    this.setContentPane(content);
    this.pack();
    this.setLocationRelativeTo(parent);
    this.setVisible(true);
}

From source file:edu.umich.robot.GuiApplication.java

/**
 * <p>//w  ww.  ja  v a  2s  .  c  o  m
 * Firing up this application requires a configuration file. If no
 * configuration file is presented on the command line, this is called to
 * prompt the user to select a configuration file.
 * 
 * <p>
 * Future work should probably include some default instead of doing this.
 * 
 * @return The selected, loaded configuration file.
 */
public static Config promptForConfig(Component parent) {

    System.out.println("CLASSPATH: " + System.getenv("CLASSPATH"));
    System.out.println("DYLD_LIBRARY_PATH: " + System.getenv("DYLD_LIBRARY_PATH"));
    System.out.println("LD_LIBRARY_PATH: " + System.getenv("LD_LIBRARY_PATH"));
    System.out.println("SOAR_HOME: " + System.getenv("SOAR_HOME"));
    System.out.println("java.library.path: " + System.getProperty("java.library.path"));

    JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt");
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    int ret = fc.showOpenDialog(parent);
    if (ret == JFileChooser.APPROVE_OPTION) {
        try {
            return new ConfigFile(fc.getSelectedFile().getAbsolutePath());
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
    return null;
}

From source file:com.stam.batchmove.SelectionFrame.java

private void importFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importFileActionPerformed
    String path = sourceDir.getText();
    if (path == null || path.trim().equals("")) {
        JOptionPane.showMessageDialog(this, "You must first select a source directory", "Error",
                JOptionPane.ERROR_MESSAGE);
        return;//ww  w .  j a  v a  2s .c om
    }

    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDialogTitle("Choose file to import");
    int retVal = fileChooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File sourceDir = new File(path);
        File[] sourceDirFilesArr = sourceDir.listFiles();
        List<File> sourceDirFiles = Arrays.asList(sourceDirFilesArr);

        File selection = fileChooser.getSelectedFile();

        List<File> files = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(selection))) {
            for (String line; (line = br.readLine()) != null;) {
                if (line != null && !line.trim().equals("")) {
                    File file = BatchMoveUtils.findFileByName(sourceDirFiles, line);
                    if (file != null) {
                        files.add(file);
                    }
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        String[] columnNames = { "", "Filename", "Size", "Status" };
        Object[][] data = new Object[files.size()][4];

        int fileNo = 0;
        for (File file : files) {
            data[fileNo][0] = file.exists();
            data[fileNo][1] = file.getAbsolutePath();
            data[fileNo][2] = file.length();
            data[fileNo][3] = file.exists() ? "Found" : "Not found";

            fileNo++;
        }

        BatchMoveUtils.showFilesFrame(data, columnNames, this);
    }
}

From source file:com.akman.excel.view.frmSelectImage.java

private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelectImageActionPerformed
{//GEN-HEADEREND:event_btnSelectImageActionPerformed
    JFileChooser chooser = new JFileChooser();

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp");
    chooser.setFileFilter(filter);/*from   w  w w. jav  a  2  s  . c o  m*/

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle("Select The Image");
    chooser.setMultiSelectionEnabled(false);
    int res = chooser.showOpenDialog(null);
    if (res == JFileChooser.APPROVE_OPTION) {

        //Saving file inside the file
        File file = chooser.getSelectedFile();

        //        if(!file.equals(filter))
        //        {
        //        JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE);
        //        return;
        //        }

        //System.out.println(file.getAbsolutePath());
        ImageIcon image = new ImageIcon(file.getAbsolutePath());

        fileName = file.getAbsolutePath();

        // Get Width And Height of PicLabel
        Rectangle rect = lblImage.getBounds();

        //System.out.println(lblImage.getBounds());
        //Scaling the image to fit in the picLabel
        Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT);
        //converting the image back to image icon to make an acceptable picLabel
        image = new ImageIcon(scaledimage);

        lblImage.setIcon(image);

        txtPath.setText(fileName);

        try {

            File images = new File(fileName);

            FileInputStream fis = new FileInputStream(images);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();

            byte[] buf = new byte[1024];

            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);
            }

            person_image = bos.toByteArray();

        } catch (Exception e) {

            JOptionPane.showMessageDialog(null, e);
        }

    }
}

From source file:eu.novait.imagerenamer.gui.MainWindow.java

protected void addFilesToList() {
    if (chooser == null) {
        chooser = new JFileChooser();
    }//from  www .  ja  v a  2 s  . c  o m
    chooser.addChoosableFileFilter(new ImageFileFilter());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    chooser.setAcceptAllFileFilterUsed(false);
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        this.setCurrentState(STATE_LOADING);
        Thread addThread = new Thread(new Runnable() {

            @Override
            public void run() {
                File[] selectedFiles = chooser.getSelectedFiles();
                loaderBar.setMaximum(selectedFiles.length);
                loaderBar.setValue(0);
                for (File f : selectedFiles) {
                    ImageFile imageFile = new ImageFile(f.getAbsolutePath());
                    imageTableModel.addImageToList(imageFile);
                    loaderBar.setValue(loaderBar.getValue() + 1);
                }
                imageTableModel.markAsChanged();
                setCurrentState(STATE_WAITING);
            }
        });
        addThread.start();
    }
}

From source file:pt.lsts.neptus.console.plugins.AirOSPeers.java

public AirOSPeers(ConsoleLayout console) {
    super(console);
    setLayout(new BorderLayout());
    chart = ChartFactory.createTimeSeriesChart(null, "Time of day", "Link Quality", tsc, true, true, true);
    chart.getPlot().setBackgroundPaint(Color.black);
    cpanel = new ChartPanel(chart);
    add(cpanel, BorderLayout.CENTER);
    cpanel.getPopupMenu().add(I18n.text("Load Addresses")).addActionListener(new ActionListener() {
        @Override/*w  w  w. j  a va  2 s.com*/
        public void actionPerformed(ActionEvent e) {
            try {
                JFileChooser chooser = new JFileChooser();
                chooser.setFileFilter(GuiUtils.getCustomFileFilter("CSV Files", "csv"));
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int op = chooser.showOpenDialog(AirOSPeers.this);
                if (op == JFileChooser.APPROVE_OPTION)
                    WiFiMacAddresses.parseAddresses(new FileReader(chooser.getSelectedFile()));
            } catch (Exception ex) {
                GuiUtils.errorMessage(getConsole(), ex);
                ex.printStackTrace();
            }
        }
    });
    cpanel.getPopupMenu().addSeparator();
    cpanel.getPopupMenu().add(I18n.text("Clear")).addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tsc.removeAllSeries();
        }
    });
}