This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Change icons in JFileChooser  RSS feed

 
Ranch Hand
Posts: 36
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: 3321
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: 61750
193
  • 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: 36
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: 36
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: 61750
193
  • 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: 61750
193
  • 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: 36
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!



 
Master Rancher
Posts: 3001
105
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!