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 / December 2005

Tip: Looking for answers? Try searching our database.

Custom Sorting FileChooserDialog

Thread view: 
jozeph78 - 01 Dec 2005 16:10 GMT
Hello. I'm attempting to create a File Chooser Dialog where the files
are displayed in a natural sort order as opposed to the lexical sort
order that Linux ls provides. This is so the files are sorted in a more
XP'ish ordering.

I already have the NaturalSortOrder Comparator that we use in other
parts of our application but I don't know how to force the
JFileChooserDialog to use my custom comparator. I tried overriding the
getFiles(File dir, boolean useFileHiding) method in the FileSystemView
that my JFileChooser uses, but that appears to not even get called.

What method actually queries the filesystem to gather the list of files
for display so I can override it to perform my own sorting before they
are shown to the user? Thank you so much for any help.
Roedy Green - 05 Dec 2005 07:10 GMT
>I already have the NaturalSortOrder Comparator that we use in other
>parts of our application but I don't know how to force the
>JFileChooserDialog to use my custom comparator.

I did not see an single method that took a Comparator so I think you
are SOL for a simple implementation.

You will have to study the code for a FileSystemView and clone Sun's
windowsFileSystemView and modify the code where in uses File.listFiles
to insert a sort after.

I noticed some code that made me feel a little queasy poking around.
What the heck is this??

FileSystemView

 public File getChild(File parent, String fileName) {
       if (parent instanceof ShellFolder) {
           File[] children = getFiles(parent, false);
           for (int i = 0; i < children.length; i++) {
               if (children[i].getName().equals(fileName)) {
                   return children[i];
               }
           }
       }
       return createFileObject(parent, fileName);
   }
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Andrey Kuznetsov - 05 Dec 2005 08:17 GMT
> I noticed some code that made me feel a little queasy poking around.
> What the heck is this??

I ask this question pretty often ;-)

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Oliver Wong - 06 Dec 2005 22:56 GMT
> I noticed some code that made me feel a little queasy poking around.
> What the heck is this??
[quoted text clipped - 12 lines]
>        return createFileObject(parent, fileName);
>    }

   There's a lot of code like that in Eclipse. They have an interface
called an IResource, which for almost all intents and purposes is a
reference to a file; except it may refer to a file which doesn't actually
exist in the file system.

   So you'd have code like the one you showed here which will try to return
a IResource which points to the actual file on the system if it exists
(which implies first checking for its existence), or create an IResource
which sort of points to where the file would be, if it existed.

   - Oliver


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.