Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JFileChooser doen't work with custom file filters, or showing hidden files #46

Closed
rvillablanca opened this issue Oct 10, 2013 · 4 comments
Assignees

Comments

@rvillablanca
Copy link

I have that code:

JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new PropertyFilter());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileHidingEnabled(false);
int response = chooser.showOpenDialog(this);

With MetalLookAndFeel, file chooser works fine, but if I install WebLookAndFeel (WebLookAndFeel.install( ) ), then it doesn't show hidden files and I can see all files.

image

image

@ghost ghost assigned mgarin Oct 10, 2013
@mgarin
Copy link
Owner

mgarin commented Oct 11, 2013

There is indeed something strange happening with filters.
I will get rid of those bugs pretty soon, thanks for reporting!

@mgarin
Copy link
Owner

mgarin commented Oct 14, 2013

I found the issue source and fixed it.
This fix will be available in v1.24 update tomorrow.

I also recommend you to extend AbstractFileFilter class when creating your own filter.
It is called DefaultFileFilter yet but will be renamed to AbstractFileFilter in update.

Here is a small example:

public class PropertyFilter extends AbstractFileFilter
{
    @Override
    public ImageIcon getIcon ()
    {
        // Your custom icon
        return WebLookAndFeel.getIcon ( 16 );
    }

    @Override
    public String getDescription ()
    {
        // Filter description displayed in combobox
        return "Property files";
    }

    @Override
    public boolean accept ( File f )
    {
        // Filter logic
        return f.getName ().endsWith ( ".properties" );
    }
}

In that case you will be able to provide an icon for your custom filter.

You can also use that filter anywhere else because it extends javax.swing.filechooser.FileFilter and implements java.io.FileFilter so you can pass it into Swing JFileChooser without any issues.

@rvillablanca
Copy link
Author

Thanks, I will try it ;)

mgarin added a commit that referenced this issue Oct 15, 2013
…hidden files display

Custom file filter description display fix
CustomFileFilter class added to simplify new filters creation
DefaultFileFilter renamed to AbstractFileFilter
WebAsyncTreeFilterField translation added
WebCheckBoxTree checkboxes can now be hidden/disabled for each node in the tree
WebCheckBoxTree recursive checking option added
DefaultTreeCheckingModel logic and speed improved
Painters improved and now support component update calls
Demo application code links highlight improvements
RSyntaxTextArea library updated
@mgarin
Copy link
Owner

mgarin commented Oct 15, 2013

Fix is now available in v1.24 release:
https://github.com/mgarin/weblaf/releases/tag/v1.24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants