Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

How to remove JFileChooser default accept all file filter?

Thread view: 
Allen - 29 Dec 2006 06:15 GMT
Accept all file filter is default for JFileChooser. I want to remove
it. How to do it?
unnimk75@gmail.com - 29 Dec 2006 07:34 GMT
> Accept all file filter is default for JFileChooser. I want to remove
> it. How to do it?
John W. Kennedy - 29 Dec 2006 16:23 GMT
> Accept all file filter is default for JFileChooser. I want to remove
> it. How to do it?

You don't. You replace it.

Signature

John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
 -- Charles Williams.  "Taliessin through Logres: Prelude"

Andrew Thompson - 29 Dec 2006 20:19 GMT
> > Accept all file filter is default for JFileChooser. I want to remove
> > it. How to do it?
>
> You don't. You replace it.

How?

My quick experiments indicate that ..
 setFileFilter(FileFilter)
.. is a poorly named ..
 addAndSelectFileFilter(FileFilter)

To actually *remove* the initial file filter,
I needed to do this..

 JFileChooser jfc = new JFileChooser();
 // the first, only, and selected filter is 'All Files'
 jfc.removeChoosableFileFilter(
   jfc.getFileFilter() );
 // ...now add the filter to an empty list
 jfc.setFileFilter(new FileTypeFilter(".java")) ;

Is there some other method, I missed?

Andrew T.
John W. Kennedy - 29 Dec 2006 20:49 GMT
>>> Accept all file filter is default for JFileChooser. I want to remove
>>> it. How to do it?
[quoted text clipped - 18 lines]
>
> Is there some other method, I missed?

If you must, and are on 1.3 or better, setAcceptAllFileFilterUsed(false).

But every user who wants to damn-well see the "all" list will curse you
for doing so.

Signature

John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
  -- Charles Williams.  "Taliessin through Logres: Prelude"

Andrew Thompson - 29 Dec 2006 21:00 GMT
> >>> Accept all file filter is default for JFileChooser. I want to remove
> >>> it. How to do it?
> >> You don't. You replace it.
> >
> > How?
...
> If you must, and are on 1.3 or better, setAcceptAllFileFilterUsed(false).

Aaah.. the marvels of ..'modern' technology
( I got away with that, didn't I? ;).

> But every user who wants to damn-well see the "all" list will curse you
> for doing so.

I'm glad you brought that up.  It is not something I
have ever attempted (till I saw your first post on it -
which got me curious).

I tend to agree that even if the end-user has no point in
openning a particular file-type in my application, I will
still offer the 'All Files' filter - so they can use it for
navigation (I am used to what most of my more common
directories *look* like in a file filter - it would be a nuisance
to have the contents 'changing' according to what flavor
of files the application likes).

The 'path of least surprise' might suggest it is better
to leave the 'All Files' filter in place.

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.