• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Change icons in JFileChooser  RSS feed

 
Ranch Hand
Posts: 35
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, ranch!

I was wondering if there is a way to change the default icons in JFileChooser? In my case i wan't to
change the icons for image files into native system icons for that type of files. I know it is possible to
do this via the UIManager class with the setLookAndFeel method but i just wan't to change specific icons
in JFileChooser more to the point those that represents image files.

Is it possible to do this with the FileSystemView or FileView classes in the filechooser package or am
i missing something if so i do apologize? So far I have begun to look closer into the FileSystemView and
FileView classes or am i completely on the wrong track?

Thanks a lot in advance!

Best regards,
Robert.
 
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I believe you can do this by extending FileView to create your own FileView class that returns the appropriate icon (from the getIcon() method) or return null to use the default icon. You register your FileView object through the setFileView method in JFileChooser.
 
Marshal
Posts: 60157
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to see you again, Tony.

I think this discussion would sit better in our GUIs forum. Moving.
 
Robert Ingmarsson
Ranch Hand
Posts: 35
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tony Docherty wrote:Yes I believe you can do this by extending FileView to create your own FileView class that returns the appropriate icon (from the getIcon() method) or return null to use the default icon. You register your FileView object through the setFileView method in JFileChooser.

 

Thanks a lot for this answer. It seems i am on the right track to accomplish this task that i have taken upon me to achieve.

Best regards,
Robert!
 
Robert Ingmarsson
Ranch Hand
Posts: 35
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, ranch!

This thread is now solved this is the code i used to change only image file icons to native system icons.



 
Campbell Ritchie
Marshal
Posts: 60157
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:. . . This thread is now solved . . .

I'm not convinced.

You meansurely? Look at the old Sun style guide.
Also, there is something unusual about that method. It can legitimately be marked static, but it would probably be a good idea to mark it final, too.
 
Campbell Ritchie
Marshal
Posts: 60157
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A few minuste ago, I wrote:. . .. . .

I think this would be even better:-
 
Robert Ingmarsson
Ranch Hand
Posts: 35
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr Ritchie!

Thank you so much for your answer and advice. I changed the method isImageFile to



... and i saw a clear advantage in my project in having this method declared static. Below is an example of code in which i use it:




Again thank you very much for your tip!

Best regards,
Robert!



 
Rancher
Posts: 2835
96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can further simplify the code that lets you only select suitable graphic files. Have a look at the class 'FileNameExtensionFilter'. It is very easy to use.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!