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 / GUI / June 2005

Tip: Looking for answers? Try searching our database.

FileDialog.setFilenameFilter()

Thread view: 
Martijn Mulder - 29 Jun 2005 09:33 GMT
I let my class implement the FilenameFilter interface and override the boolean
accept(File,String)-method. Even if I let this function return false in every
case, still all files in the directory are displayed. Here is some code:

//open method
String open()
{
 java.awt.FileDialog a=new java.awt.FileDialog
 (
  frame,
  "Open een .jpg of .img file",
  java.awt.FileDialog.LOAD
 );
 a.setFilenameFilter(this);
 a.setVisible(true);
 return a.getFile();
}

//accept, doesn't work
public boolean accept(java.io.File a,String b)
{
 return false;
}
Skip - 29 Jun 2005 09:30 GMT
> I let my class implement the FilenameFilter interface and override the boolean
> accept(File,String)-method. Even if I let this function return false in every
[quoted text clipped - 13 lines]
>   return a.getFile();
>  }

Javadoc:

public void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified
filter. Filename filters do not function in Sun's reference implementation
for Microsoft Windows.

What on Earth where they thinking...
Martijn Mulder - 29 Jun 2005 13:11 GMT
>> I let my class implement the FilenameFilter interface and override the
boolean
> > accept(File,String)-method. Even if I let this function return false in
every
> > case, still all files in the directory are displayed. Here is some code:
> >
[quoted text clipped - 11 lines]
> >   return a.getFile();
> >  }

> Javadoc:
>
[quoted text clipped - 4 lines]
>
> What on Earth where they thinking...

Stupid. I do the file testing by hand now with a variation
of this code. What made the Sun people ommit a proper
implementation of FilenameFilter for Window$?

//open method
String open()
{
 java.awt.FileDialog a=new java.awt.FileDialog
 (
  this,
  "Open een .jpg of .img file",
  java.awt.FileDialog.LOAD
 );
 a.setVisible(true);
 String b=a.getFile();
 if(b.endsWith(".jpg")|b.endsWith(".gif");
 else b="";
 return b;
}
Martijn Mulder - 29 Jun 2005 14:59 GMT
> I let my class implement the FilenameFilter interface and <snip>

You know what? I'll use JFileChooser instead.

Where would I be without this newsgroup...
Skip - 29 Jun 2005 15:12 GMT
> > I let my class implement the FilenameFilter interface and <snip>
>
> You know what? I'll use JFileChooser instead.
>
> Where would I be without this newsgroup...

Unfortunately JFileChooser has it's own trouble like poor performance and
doesn't really 'feel' like a native widget.

Always be sure to use the native LookAndFeel or it will look so crap you
eyes will pop out.

~~~
     try
     {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     }
     catch (Exception exc)
     {
        // we failed miserably
     }
~~~

Anyway, I wish you luck
Martijn Mulder - 29 Jun 2005 15:25 GMT
>>> I let my class implement the FilenameFilter interface and <snip>

>> You know what? I'll use JFileChooser instead.

<snip>

> Always be sure to use the native LookAndFeel or it will look so crap you
> eyes will pop out.
[quoted text clipped - 9 lines]
>          // we failed miserably
>       }

Yeah, that's good advice. It still looks kind of weird but gone are the
purple scrollbars :-)


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.