File Filter in AWT

The FileDialog class in AWT does not include a file filter! The FileFilter class doesn't work properly, I tried using it in different ways, but it doesn't filter the files.
How can this be achieved?
TECHNOSAM.

Using setFile("*.txt") works, but it has limitations.
Once some file is clicked, the Filter effect is lost. There has to be some why by implementing the FilenameFilter interface. It's accept method can be implemented. I tried this method, but doesn't work. Or there could be some mistake in the way I have done it. This is the way i have done it:
class MyFilter implements FilenameFilter
public MyFilter() {}          
public boolean accept(File dir,String name)
if(name.endsWith("gif") || name.endsWith("jpg"))
return true;
return false;
FileDialog fd = new FileDialog(parent,"File Open...");
MyFilter f = new MyFilter();
fd.setFilenameFilter(f);
Is this alright? This does no good. Does somebody have a solution to this problem?
Thanks,
TechnoSam.

Similar Messages

  • JFileChooser: folder disapper for choosing when file filter is set

    I have created a JFileChooser for saving csv file. After I have add .csv as the choosable file filter, all folders disapper even though I have set file selection mode as FILES_AND_DIRECTORIES! It will be shown only when I choose "All files" in the file type. Is there any way to display the folder together with all the csv files together?
    Here is my code sippnet:
    javax.swing.JFileChooser saveDialogBox = new javax.swing.JFileChooser("C:\\");
    saveDialogBox.setDialogTitle("Exporting...");
    saveDialogBox.setDragEnabled(true);
    saveDialogBox.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
    FileFiltering fileExtension = new FileFiltering();
    saveDialogBox.addChoosableFileFilter(fileExtension);               
    int retMethod = saveDialogBox.showSaveDialog(this);

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.filechooser.*;
    public class Test extends JFrame {
        public Test() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container content = getContentPane();
         JFileChooser jfc = new JFileChooser();
         jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
         jfc.setFileFilter(new FileFilter() {
             public boolean accept(java.io.File file) {
              return file.isDirectory() || file.getName().endsWith(".txt");
             public String getDescription() { return "*.txt"; }
         jfc.showSaveDialog(this);
         setSize(200,200);
         show();
        public static void main(String[] args) { new Test(); }
    }

  • Obiee upload file filter

    Hi,
    In Obiee 11g, i'am using the new functionnality of file uploading. However, i would kniw if it's possible to do add a file filter? I want only .doc files to uploaded.
    Thanks.

    OK,
    Using firebird, i found the right JS file. I didn't finished the filter yet because i have also to check that i am in the right folder but i think i am in the right way.
    Thanks.
    However, if a new patch is installed, there is a risk to have my customizations delete. There is way to prenvent this ?

  • File filter removing the All Files option

    I am trying to remove the All Files option from the file filter. Someone suggested doing this:
        public FileFilter getAcceptAllFileFilter() {
          return null;
        }but I am unsure how to use it. My filechooser is this:
          final JFileChooser fc = new JFileChooser();
          fc.setFileFilter(new ExtensionFileFilterClass());ExtensionFileFilterClass is used to filter out some extensions and only keep .txt ones. It works except for the All Files part. Can anyone point me in the right direction? Thanks.
    Allyson

    I think my subject is probably misleading. I WANT to remove the All Files option. I only want to have the *.txt option on the filter. And it won't go away. Can I make it go away? I only want the user to have the ability to pick from *.txt files, not any. Thanks.
    Allyson

  • How to set file filter in FileUpload?

    Is there any way to set the file filter on FileUpload? Let's say, I only want the user to see all .xml files. Currently, the default is all files of any extension are displayed.
    Thanks. c",?

    The dialog which appears is solely controlled by the browser. I don't see a way to set the file filter to this dialog.
    You can read more about file upload here.
    http://jakarta.apache.org/commons/fileupload/using.html
    - Winston
    http://blogs.sun.com/winston

  • File filter in jdeveloper

    hi Forum
    plz help me write a file filter in jdeveloper.i need to filter *.class and *.jar.
    divya

    Hi,
    in your code you can:
    boolean designtimeChecked = false;
    boolean isDesigntime = false;
    if (!designtimeChecked){
    //prevent this code being executed in designtime
    FacesContext fctx = FacesContext.getCurrentInstance();
    HttpServletRequest rq = (HttpServletRequest)fctx.getExternalContext().getRequest();
    isDesigntime = rq.getServerPort()==-1;
    designtimeChecked=true;
    later on you just call if (!isDesigntime){
    // execute code
    Frank

  • File Filter

    Hi,
    How Can I create file filter? I Need to show only the specyfic type of file
    in JFileChooser open or save ?
    Best Regards,
    Gutek

    You have to subclass the javax.swing.filechooser.FileFilter abstract class, add your filter object to your JFileChooser user-choosable filters list ( addChoosableFileFilter() method) and make it current ( setFileFilter() method ).
    Look at this:
    /** A simple FileFilter discriminating files by extension
    *  (only regular files allowed)
    *  @author Giorgio Maone
    import java.io.File;
    import javax.swing.filechooser.*;
    import javax.swing.JFileChooser;
    public class ExtensionFileFilter extends FileFilter {
    String[] extensions;
    String desc;
      public ExtensionFileFilter(String desc,String[] extensions) {
      this.extensions=extensions!=null?extensions:new String[]{};
      this.desc=desc==null?extList():desc+" ("+extList()+")";
    private String extList() {
      int len=extensions.length;
      if(len>0) {
       String ret=extensions[0];
       for(int j=1; j<len; ret+=", "+extensions[j++]);
       return ret;
      } else return "";
      public boolean accept(File f) {
      if(f.isFile()) {
       String fname=f.getName().toLowerCase();
        for(int j=extensions.length; j-->0;) {
         if(fname.endsWith(extensions[j])) return true;
      return false;
      public String getDescription() {
        return desc;
    //test main
      public static void main(String[] args) {
      JFileChooser fc=new JFileChooser();
      fc.addChoosableFileFilter(new ExtensionFileFilter("Pictures",new String[]{".gif",".jpg",".jpeg",".png"}));
      fc.addChoosableFileFilter(new ExtensionFileFilter("Audio-clips",new String[]{".au",".aiff",".mp3",".wav"}));
      fc.addChoosableFileFilter(new ExtensionFileFilter("Movies",new String[]{".mpg",".mpeg",".avi"}));
      fc.setAcceptAllFileFilterUsed(false);
      fc.setDialogTitle("Select a multimedia content");
      fc.showOpenDialog(null);
    }

  • File filter on F4

    Hi,
    I'm using the method below to allow the user to select a file from their local drive. The file filter *.txt parameter does not work though, all it does is put .txt in the File Type and not allow you choose any other type - but it shows ALL files. I want the user to just see the .txt's in their local drive. Thanks
    Get file specified on selection screen
       CALL METHOD cl_gui_frontend_services=>file_open_dialog
         EXPORTING
           default_extension = 'TXT'
           file_filter       = '*.txt'
         CHANGING
           file_table        = gt_filename_tab
           rc                = g_filerc.

    Hi,
    Try it this way
    DATA : gt_filename_tab type filetable,
           g_filerc type i.
    PARAMETERS : FILE TYPE STRING.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
    default_extension = 'TXT'
    file_filter = '(*.txt)|*.txt|'
    CHANGING
    file_table = gt_filename_tab
    rc = g_filerc.
    Regards

  • Setting Self Created File Filter as Default

    Hello Guys,
    I need some help out here. I have created a simple file filter and I have added it to a JFileChooser. Now when the FileChooser Dialog is loaded it shows the All Files Filter whereas I want the mine to be the default filter when the dialog loads. Also I do not want the Default File Filter (All Files) to be disabled. So both the filters should be enabled with my filter loading as default at runtime. Please Help.

    Here is the sample code,
    //=====================================================================
    //Assuming that you have a JFileChooser object created by the reference fileChooser
    JFileChooser fileChooser = new JFileChooser();
    //To disable the default select all FIleFIlter call setAcceptAllFIleFilterUsed(false);
    fileChooser.setAcceptAllFIleFilterUsed(false);
    //set your desired FileFIlter
    //Please note that the last filter is the one selected by default
    //Suppose you have three FileFIlters namely
    //FIleFIlterA, FIleFIlterB,FIleFIlterC
    //fileChooser.setFileFIlter(yourFIlterA);
    //fileChooser.setFileFIlter(yourFIlterB);
    //fileChooser.setFileFIlter(yourFIlterC);
    //Now FIleFIlterC will be shown selected by default
    fileChooser.setFileFIlter(yourFIlter);
    //Call any of the showDialog methods to open a dialog
    fileChooser.showDialog(null, "Select File");
    //===========================================================================
    Hope this will solve your problem
    Best regards,
    MMM

  • Addition of jar files to an AWT MI project

    Hi,
    I need to add two jar files to my project. These jar files contain GUI component classes.
    When I import the jar files to <My APP>/classes, they are visible. Once I build the project, they are removed.
    How can I add those jar files to my project.
    Regards
    Raja Sekhar

    Hi Raja
    I got a similar problem as you. I tried to add external jar files to my AWT project. I also exported through 'Export Jar / Zip File' option in NWDS. But I could not reimport it or use it in MI Client. I finally created a addon and assigned to the client device. It worked fine. I could access the addon classes in my AWT applications.
    Check out this Links
    External API in MI application
    Hope it helps
    Regards,
    Rakesh ;>)

  • Checking a file filter

    I've managed to create a file saver dialog, with some custom file filters, called JpegSave and PPM save.
    I'm trying to check, once a file saver dialog has been created, to check what the current file filter is.
    Is it possible to check, by writing some code, whether the current file saver dialog's file filter is a certain file filter?

    Thanks, but that doesn't seem to work.
    Wouldn't that code just create a new FileFilter and
    set it to the current filter?
    I'm trying to find out what the current filter is and
    check if it is the same as a certain file filter
    getFileFilter() returns to you the file filter that is currently in use by the JFileChooser. If you want to compare it with another file filter to see if it is the same, do:
    if (filter == getFileFilter()) { .. }
    Most likely, though, what you really would want to do is see if it's the same TYPE of file filter. So you'd want to do something like:
    if (fileChooser.getFileFilter() instanceof filter.getClass()) { .. }

  • File Filter for a Jlist

    I'm new to filtereing, ive been looking on site and this one, but can't quite get round the filtering process.
    Most filter examples I've seen are for Filechooser, but this program is a Jlist.
    I wish to show only one file type, namely an AVI format.
    Can anyone help
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.io.File;
    import java.io.FileFilter;
    class Test2 extends JFrame
      DefaultListModel dim = new DefaultListModel();
      JList list = new JList(dim);
      private FileFilter fileFilter;
      public Test2()
        setLocation(200,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JScrollPane sp = new JScrollPane(list);
        sp.setPreferredSize(new Dimension(150,200));
        FNameFilter filter = new FNameFilter();
        File directory = new File(".");
        File[] files = directory.listFiles(filter);
        for(int x = 0; x < files.length; x++)
            if(files[x].isFile()) dim.addElement(files[x].getName().toLowerCase().endsWith("txt"));
        JPanel panel = new JPanel();
        JButton btn = new JButton("Delete File");
        panel.add(btn);
        getContentPane().add(sp,BorderLayout.CENTER);
        getContentPane().add(panel,BorderLayout.SOUTH);
        pack();
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            int selectedIndex = list.getSelectedIndex();
            if(selectedIndex < 0)
              JOptionPane.showMessageDialog(null,"Please select file to delete");
            else
              File fileToDelete = new File((String)list.getSelectedValue());
              if(fileToDelete.delete()) dim.removeElementAt(selectedIndex);
       public static void main(String[] args){new Test().setVisible(true);}
    }

    I tried FileFilter, but the system wouldn'y excpt
    that.
    Would it be directly related to the file only.Just how did you try "FileFilter"? You know that you have to implement one first, don't you?

  • Upload file - filter problem

    Hi all,
    I have a problem with upload file using JSF RI 1.1 + tomahawk.
    I think that the problem is in the web.inf filter definition because I get these warns:
    17:11:51,875 WARN Digester:127 - [ConverterRule]{faces-config/converter} Merge(null,java.math.BigDecimal)
    17:11:51,890 WARN Digester:127 - [ConverterRule]{faces-config/converter} Merge(null,java.math.BigInteger)
    17:11:52,578 WARN ExtensionsFilter:34 - Please adjust your web.xml to use org.apache.myfaces.webapp.filter.ExtensionsFilter
    And also this error when I click in a button to go to the upload page:
    16:47:47,250 WARN ReducedHTMLParser:468 - Invalid HTML; bare lessthan sign found at line 127
    When I click in the button to go to the upload pages the first time i get this error ad with the second click I get the right page.
    It seems like he go to the filter the first time and then to the faces servlet the second, it is possible?
    this is the code of the web.xml:
    <filter>
            <filter-name>MyFacesExtensionsFilter</filter-name>
            <filter-class>
                org.apache.myfaces.component.html.util.ExtensionsFilter
            </filter-class>
            <init-param>
                <param-name>uploadMaxFileSize</param-name>
                <param-value>10m</param-value>
            </init-param>
            <init-param>
                <param-name>uploadThresholdSize</param-name>
                <param-value>100k</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>MyFacesExtensionsFilter</filter-name>
            <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>
        And this is the code of the page with upload:
    <h:form id="upload" enctype="multipart/form-data" >
                    <h:outputText value="Gimme an image: "/>
                    <t:inputFileUpload id="fileupload"
                    value="#{fileUploadBean.myFile}"
                    storage="file"
                    required="true"/>
                    <h:commandButton value="load it up" action="#{fileUploadBean.upload}" />
                </h:form>Anyone can help?
    Thanx very much!
    Message was edited by:
    -Frizzi-

    I don't have org.apache.myfaces.webapp.filter.ExtensionsFilter in my libraries, I only have org.apache.myfaces.component.html.util.ExtensionsFilter. I also tried to change it, but it still don't work...
    I tried to redo all the process, and now I can't even access the action method in my backing bean....
    I repost the the file that I use:
    This is the error that I get when I try to use the action method:
    16:24:11,203  WARN ReducedHTMLParser:468 - Invalid HTML; bare lessthan sign found at line 135
    16:24:11,203  WARN ReducedHTMLParser:468 - Invalid HTML; bare lessthan sign found at line 180 web.inf snippet:
    <filter>
            <filter-name>extensionsFilter</filter-name>
            <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
            <init-param>
                <param-name>uploadMaxFileSize</param-name>
                <param-value>100m</param-value>
                <description>Set the size limit for uploaded files.
                    Format: 10 - 10 bytes
                            10k - 10 KB
                            10m - 10 MB
                            1g - 1 GB
                </description>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>extensionsFilter</filter-name>
            <url-pattern>*.shtml</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>extensionsFilter</filter-name>
            <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>JSF page:
    <h:form id="upload" enctype="multipart/form-data" >
                    <h:outputText value="Gimme an image: "/>
                    <t:inputFileUpload id="fileupload"
                    value="#{fileUploadBean.myFile}"
                    storage="file"
                    required="true"/>
                    <h:commandButton value="load it up" action="#{fileUploadBean.upload}" />
                </h:form>BackingBean:
    public class FileUploadBean {
        private UploadedFile myFile;
        private static Logger log =Logger.getLogger(FileUploadBean.class);
       public String upload() {
            log.info("FileUploadBean.upload");
            try {
            log.info("fileupload_isfile?"+ getMyFile().getBytes());
            log.info("fileupload_path"+ getMyFile().getSize());
            log.info("fileupload_name" + getMyFile().getName());
            System.out.println("myFilename" +getMyFile().getName());
            catch (Exception e){
                log.info("Errore nell'upload");
            return "ok";
        }Please help... I don't know how to solve it. Coul anyone post me a simple WORKING example?
    Thanx a lot!!

  • IDOC to XML file filter

    Hi Experts,
    I have created a custom IDOC message type and send as XML file outbound. In the XML file, there are other details as follows just before my header data. Is there any filter for this? The requirement is only send the header and item data.
    Please note that these fields are not defined in my custom IDOC type.
    - <IDOC BEGIN="1">
    - <EDI_DC40 SEGMENT="1">
      <TABNAM>EDI_DC40</TABNAM>
      <MANDT>200</MANDT>
      <DOCNUM>0000000000250025</DOCNUM>
      <DOCREL>700</DOCREL>
      <STATUS>30</STATUS>
      <DIRECT>1</DIRECT>
      <OUTMOD>2</OUTMOD>
      <IDOCTYP>ZIDOCTYP</IDOCTYP>
    Thanks in advance.

    Hi,
    in XI side don't map control data field to your traget strucutre
    Thanks
    Amit

  • IDoc - File filter in Message Mapping

    I'm trying to move employees from an IDoc to a File.  I want to filter on field E1BEN31-LEVL1 and only create ROW in the FILE if E1BEN31-LEVL1 = '1000'.  How do I do this?
    Source: 1 single IDoc with multiple employees in it
    BENEFIT3->
               IDOC->
                        E1BEN01->
                                     E1BEN02-> (different E1BEN02 segment for each employee)
                                              BEGDA
                                              ENDDA
                                              LEVL1 (filter field)
                                              etc.
    Target: File with multiple line items
    FILE->
             ROW-> (should be a ROW for each E1BEN02 segment in the IDoc)
                   NAME
                   ADDRESS
                   etc.

    Hi. Susan
    Use graphic functions.
    LEVL1----
    >
    > equalS -
    >ifwithoutelse
    Constant  '1000'--- >
    E1BEN02----
    > then -
    >>ROW - Target
    Edited by: Luis Ortiz on Aug 12, 2010 3:10 PM

Maybe you are looking for