Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to add thumbnail view mode in jfilechooser  RSS feed

 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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 thumbnail view mode . is there a clean and easy way to achieve this ?

thanks in advance.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there's no 'clean and easy' way, since JFileChooser doesn't expose an API for what you want.

There is a hackish way, at least for the default Metal look'n'feel: drill down through the file chooser's component hierarchy till you hit a component of type sun.swing.FilePane, obtain a reference to the file pane's VIEWTYPE_DETAILS Action, and trigger that Action's actionPerformed(...).

This SSCCE uses my Swing Utils class to obtain a reference to the FilePane, but you can easily write your own drilldown method using recursion.Note that this code makes use of a proprietary Sun class which is an internal implementation detail and subject to change or removal in future Java versions. However, Swing has been declared to be in maintenance mode, so the chances of that happening are next to nil.

An alternative approach which avoids the use of proprietary API but is no less implementation dependent is to get a reference to the details view button and click it programatically.
To understand how I reached these solutions, read the source code for MetalFileChooserUI#installStrings(...) (line 489 in Java SE 6).
 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir

i didn't understood what you mean by this i didn't got the swing utils class .please show me an example how it works..

Thanks in advance
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are few solutions given here, though I haven't tested myself.

http://stackoverflow.com/questions/4096433/making-jfilechooser-show-image-thumbnails
 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
swastik
it is not working i need all the files to be displayed thumbnail mode using file chooser....pl z help me
thanks in advance
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prajna,

JFileChooser seems to be missing this. You may try the older FileDialog from java.awt. I haven't found how to make the thumbnail view default, but at least it shows option for that unlike JFileChooser that has only two options.

 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
swastik
no i had tried but still it is showing in the list mode only... any one help me
thanks in advance.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prajna,

Agreed to what you are saying, but it does have options to change the view to Extra Large Icons, Large Icons etc, probably you don't get that with JFileChooser.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!