How to remove JFileChooser default accept all file filter?

Discussion in 'Java' started by Allen, Dec 29, 2006.

  1. Allen

    Allen Guest

    Accept all file filter is default for JFileChooser. I want to remove
    it. How to do it?
     
    Allen, Dec 29, 2006
    #1
    1. Advertising

  2. Allen

    Guest

    Allen wrote:
    > Accept all file filter is default for JFileChooser. I want to remove
    > it. How to do it?
     
    , Dec 29, 2006
    #2
    1. Advertising

  3. Allen wrote:
    > Accept all file filter is default for JFileChooser. I want to remove
    > it. How to do it?


    You don't. You replace it.

    --
    John W. Kennedy
    "The blind rulers of Logres
    Nourished the land on a fallacy of rational virtue."
    -- Charles Williams. "Taliessin through Logres: Prelude"
     
    John W. Kennedy, Dec 29, 2006
    #3
  4. John W. Kennedy wrote:
    > Allen wrote:
    > > 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.
     
    Andrew Thompson, Dec 29, 2006
    #4
  5. Andrew Thompson wrote:
    > John W. Kennedy wrote:
    >> Allen wrote:
    >>> 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?


    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.

    --
    John W. Kennedy
    "The blind rulers of Logres
    Nourished the land on a fallacy of rational virtue."
    -- Charles Williams. "Taliessin through Logres: Prelude"
     
    John W. Kennedy, Dec 29, 2006
    #5
  6. John W. Kennedy wrote:
    > Andrew Thompson wrote:
    > > John W. Kennedy wrote:
    > >> Allen wrote:
    > >>> 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.
     
    Andrew Thompson, Dec 29, 2006
    #6
  7. Allen

    Mean Mike

    Joined:
    Sep 18, 2013
    Messages:
    1
    Location:
    Ottawa, Ontario, Canada
    Just put All Files as last option

    Instead of completely remove the All Files option, try adding to the end by first removing it. It gets automatically added as the first entry, not my favorite either.

    JFileChooser fc = new javax.swing.JFileChooser();
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileNameExtensionFilter("Batch Files (*.bat)", "bat"));
    fc.addChoosableFileFilter(new FileNameExtensionFilter("Text Files (*.txt)", "txt"));
    fc.setAcceptAllFileFilterUsed(true);
     
    Mean Mike, Sep 18, 2013
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand Gopinath

    JFileChooser and file filter events

    Anand Gopinath, May 27, 2004, in forum: Java
    Replies:
    0
    Views:
    853
    Anand Gopinath
    May 27, 2004
  2. SV
    Replies:
    2
    Views:
    4,075
    Andrew Thompson
    Oct 29, 2004
  3. Replies:
    5
    Views:
    11,165
    I82Much
    Jun 3, 2009
  4. Ramon F Herrera
    Replies:
    3
    Views:
    487
    Ramon F Herrera
    Nov 13, 2007
  5. Nicolae Fieraru

    Filter digits, accept input from numpad

    Nicolae Fieraru, Dec 19, 2004, in forum: Javascript
    Replies:
    4
    Views:
    175
Loading...

Share This Page