JFileChooser notes

We get file

by using getSelectedFile() method, which return the File object.

The open/close button

can be disabled by using setControlButtonsAreShown(false) method.

File filter

can be add using: setFileFilter(new Xlsfilter());


class Xlsfilter extends FileFilter
    public boolean accept(File f) {
        return f.isDirectory() || f.getName().toLowerCase().endsWith(".xls") || f.getName().toLowerCase().endsWith(".xlsx");

    public String getDescription() {
        return "Xls files";


we can hide the accept/cancel buttons by calling chooser.setControlButtonsAreShown(false) when detect any selecting change on files/directories:

fileChooser.addPropertyChangeListener(new PropertyChangeListener()
            public void propertyChange(PropertyChangeEvent evt)
                if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName()))
                    File file = (File) evt.getNewValue();

                    if (file != null && file.isFile() && file.getName().contains("xls"))

                    else if (file != null)





One comment

  1. no cold calling definition · May 24, 2013

    Thank you, I’ve just been looking for information about this topic for ages and yours is the best I’ve came upon till now.
    However, what concerning the bottom line? Are you positive about the supply?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s