• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Change icons in JFileChooser

 
Ranch Hand
Posts: 214
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 214
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 214
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

I think this would be even better:-
 
Robert Ingmarsson
Ranch Hand
Posts: 214
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!



 
Saloon Keeper
Posts: 5656
214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic