• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

default JFileChooser to details view Mode

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

thanks.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
othman
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
reply
    Bookmark Topic Watch Topic
  • New Topic