jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes default JFileChooser to details view Mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "default JFileChooser to details view Mode" Watch "default JFileChooser to details view Mode" New topic

default JFileChooser to details view Mode

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi all,

In JFileChooser there are 2 JToggleButtons : "details" and "List.".
each one switch the file chooser to corresponding view.the default is List view mode.

I want my filechooser to always default to details view mode . is there a clean and easy way to achieve this ?

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Two options come to mind. One way is to traverse the Component hierarchy, identify the
JToggleButton and either disable or remove it. The other way is to extend and alter the
plaf code to customize the ui; this is often fairly straight-forward. For JFileChooser
this leads us to the MetalFileChooserUI in which the ui components are assembled. In the
source code (j2se 1.5) for this class, just under the class declaration, is this comment:
// Much of the Metal UI for JFilechooser is just a copy of
// the windows implementation, but using Metal themed buttons, lists,
// icons, etc. We are planning a complete rewrite, and hence we've
// made most things in this class private.
So you would end up copying and modifying almost the entire class to get anything useful.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Thank you Craig for this excellent code: this is exactly what i need & it works great !

BTW : for the treetable dnd issue; it caused me lots of problems especially on Mac os platform.so i gave up and tried to switch to a Filechooser which i suppose is simpler.

I'm happy now i have the details view of filechooser as default (thanks to your excellent code). I'm now looking to add DnD to my filechooser as i did for treetable before (u remember ?)
i want to be able to drag multiple files /folders from filechooser and drop them to right JTable as in my previous code.
I wonder if you can assist me on this if you have enough time that would be very nice from your part.

again can't thank you enough.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

My God : those Macs are driving me crazy !
I tested the java code on the Mac but didn't get the details view..
it seems Mac is using it's own view Mode different from win & Linux.
I'm stuck with theses Macs OS :they refuse to run my java code whatever I'm doing..and they say java is cross platform !!!

any way I hope i can implement dnd for filechooser at least.

thank you Craig
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi Craig,
I have a java code to hack the FileChooserUI class below...
i think we can extract the Panel createDetailsView() but the problem is there are no event listner registered on this JPanel. is that correct ?
if i display this JPanel in a JFrame and double click a folder nothing happens.

can we extract this Jpanel with all event registered as in original JFileChooser ?

the code:

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I didn't have much patience for trying to extract components from the MetalFileChooserUI.
It seems that it's the filePanel that you'd want from it. So I made up a custom component
to look like the filePanel component used in the JFileChooser. I set in the top of a
JFrame with no controls to create a minimal demonstration of drag_n_drop/copy_paste to the
similarly-configured JTable in the bottom half. The app successfully copies to Wordpad as
well as drop/pasting to the drop (lower) table. I used all String types in the fileTable
(top) component for simplicity.

It is sorta covered in the JavaRanch Style Guide.
subject: default JFileChooser to details view Mode
Similar Threads
"Details View" in JFileChooser
using FileDialog for to select both files AND directories
URLyBird Packaging
Thumbnail view on JFileChooser