File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes excluding files using FileFilter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "excluding files using FileFilter" Watch "excluding files using FileFilter" New topic
Author

excluding files using FileFilter

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

"Application-controlled filtering
The application determines which files are shown. Create a custom subclass of FileFilter, instantiate it, and use the instance as an argument to the setFileFilter method. The installed filter is displayed on the list of user-choosable filters. The file chooser shows only those files that the filter accepts."
Sourced from here.

1. I'm trying to figure out how to disable
a) a single .ini file that is specifically named within JFileChooser chooser
b) all .ini files from appearing as allowed file types within JFileChooser chooser

2. I can't figure out why the compiler is not compiling this line




Compile error
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestFileChooser.java:64: setFileFilter(javax.swing.filechooser.FileFilter) in javax.swing.JFileChooser cannot be applied to (CustomFilter)
chooser.setFileFilter(disabled);
^
1 error

Tool completed with exit code 1



Related linkshttp://www.java2s.com/Tutorial/Java/0180__File/CreatecustomFilefilter.htm" target="_new" rel="nofollow">this code snippet





Jon
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Import javax.swing.filechooser.FileFilter instead of java.io.FileFilter.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
You have several outstanding postings where we are waiting for more information from you in order to provide you with an answer. If a question is important enough to ask on a forum, then you should follow the posting to its conclusion so you aren't wasting our time.

Again in this posting you posted almost 100 lines of code which is completely unnecessary.

First of all you said the code was copied from the Swing tutorial. So why did you not download the example code and run it? Why did you not compare the working code with your code to see what is different?

Then if you don't see the difference, why did you not create a SSCCE? Again the question is about adding a FileFilter to a file chooser.

So all you need is a file chooser and a file filter. That should be about 15-20 lines of code to text the simple concept of adding a filter to the chooser.

All the other code is completely irrelevant to your question.

Learn how to write simple test programs to test new concepts that you are trying to learn, instead of writing the complete program and then do your testing.

You are taking advantage of the people on the forum who I'm sure will soon tire or your questions, given your unwillingness to simplify the questions and code.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Rob Camick wrote:You have several outstanding postings where we are waiting for more information from you in order to provide you with an answer. If a question is important enough to ask on a forum, then you should follow the posting to its conclusion so you aren't wasting our time.

Again in this posting you posted almost 100 lines of code which is completely unnecessary.

First of all you said the code was copied from the Swing tutorial. So why did you not download the example code and run it? Why did you not compare the working code with your code to see what is different?

Then if you don't see the difference, why did you not create a SSCCE? Again the question is about adding a FileFilter to a file chooser.

So all you need is a file chooser and a file filter. That should be about 15-20 lines of code to text the simple concept of adding a filter to the chooser.

All the other code is completely irrelevant to your question.

Learn how to write simple test programs to test new concepts that you are trying to learn, instead of writing the complete program and then do your testing.

You are taking advantage of the people on the forum who I'm sure will soon tire or your questions, given your unwillingness to simplify the questions and code.


Well it's not completely copied, I try to interpret what I read, and, in any case I can't create an SSCE if I have a compilation error, and, I'm wondering how to resolve it.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
So you start with something that works.

Then you make a change and retest. If it works great, if not you know what you changed and should be able to solve the problem or ask a specific question.

And again you don't test new code by embedding it into your current application. You test it standalone to that you understand the basic concepts. Then you add it into your application.

You keep trying to run instead of learn how to walk and move slowly. Then you expect use to find your mistakes.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Jon Camilleri wrote:I can't create an SSCE if I have a compilation error

Did you even go through the SSCCE page?
Either the example compiles cleanly, or causes the exact error message about which you want help.


luck, db
There are no new questions, but there may be new answers.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Darryl Burke wrote:
Jon Camilleri wrote:I can't create an SSCE if I have a compilation error

Did you even go through the SSCCE page?
Either the example compiles cleanly, or causes the exact error message about which you want help.


Well I have given the issue further thought, and, came up with a code snippet that still confirms the issue; although desktop.ini,
which is hidden by default within Windows XP windowing system does not show up I have a feeling that it due to the fact that it is hidden,
since the filter includes the "Windows Initialization Files", for which I have passed a CustomFilter object indicating false as the third parameter,
to the JFileChooser object chooser, which should mean that the chooser would disable them, however, I think that the behaviour is not inherent
within JFileChooser.


Further references
1. Core Java Volume I (8th Edition) P.476-478.
2. Issue 7045122



[Thumbnail for scr.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Jon Camilleri wrote:Well I have given the issue further thought, and, came up with a code snippet that still confirms the issue; although desktop.ini,
which is hidden by default within Windows XP windowing system does not show up I have a feeling that it due to the fact that it is hidden,
since the filter includes the "Windows Initialization Files", for which I have passed a CustomFilter object indicating false as the third parameter,
to the JFileChooser object chooser, which should mean that the chooser would disable them, however, I think that the behaviour is not inherent
within JFileChooser.

Passing false for the third parameter tells the file filter to not include it, therefore you will never see any ini files.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Rob Spoor wrote:
Jon Camilleri wrote:Well I have given the issue further thought, and, came up with a code snippet that still confirms the issue; although desktop.ini,
which is hidden by default within Windows XP windowing system does not show up I have a feeling that it due to the fact that it is hidden,
since the filter includes the "Windows Initialization Files", for which I have passed a CustomFilter object indicating false as the third parameter,
to the JFileChooser object chooser, which should mean that the chooser would disable them, however, I think that the behaviour is not inherent
within JFileChooser.

Passing false for the third parameter tells the file filter to not include it, therefore you will never see any ini files.


Did I miss anything out? because I would like to exclude it from the list of options from the list of options that JFileChooser provides to the user, since it gives a misleading impression by including that option (see screenshot attached).
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I understood from your post that you were wondering why desktop.ini is hidden, and you deduced it's because the file is hidden in Windows. It's not though, it's because you are telling your CustomFileFilter to hide (allow == false) all ini files. When anyone selects that file filter all ini files will be removed from the file list. Therefore, the hiding of ini files is exactly what you told the JFileChooser to do.
 
wood burning stoves
 
subject: excluding files using FileFilter
 
Similar Threads
Only accept a file type in JFileChooser ?
[error] error: Class names, 'JFileChooser', are only accepted if annotation processing is explicit
FileChooser customization
JFileChooser!
JFileChooser