This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 62893
203
  • 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: 62893
203
  • 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: 62893
203
  • 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: 3080
108
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!