We help IT Professionals succeed at work.

How to scale an icon returned by JFileChooser.get

Computer07
Computer07 asked
on
Medium Priority
366 Views
Last Modified: 2012-05-11

I am using jlist to display the file name and associated icon based on the extension. For example if file is pdf file it display pdf icon and name of file. I get icon with following code:
 
JFileChooser chooser = new JFileChooser( );
Icon fileIcon = chooser.getIcon( file );

But the icon returned is of small size. How can i scale the icon without without loosing the quality of icon and then how to convert icon to image icon so that i can use it in JLabel.

Please provide code snippets. I have no idea of java graphics.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Why not just use your own icon?
Awarded 2011
Awarded 2011

Commented:
Even though the questyion is about different issue I guess  in
the code they show how to scale:

http://stackoverflow.com/questions/4096433/making-jfilechooser-show-image-thumbnails
CERTIFIED EXPERT
Top Expert 2016

Commented:
btw, in most cases, you can never scale up without loss of image quality. Much better to start out with the correct size

Author

Commented:
i think i should be very clear about my question.My question is :
 How Can i scale a icon (not imageicon) without loosing quality.  

Please provide a code snippet for this.
CERTIFIED EXPERT
Top Expert 2016

Commented:
>> How Can i scale a icon (not imageicon) without loosing quality.  

As i've just said - you can't (because you want to enlarge it)
CERTIFIED EXPERT
Top Expert 2016

Commented:
You might be lucky in not perceiving too much difference, but the image WILL be degraded due to interpolation. Why not just start out with the correct size of your choice?

Author

Commented:
Can any body provide me the exact solution for this????
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you're determined to scale it up, use an AffineTransform:

http://www.java2s.com/Code/Java/2D-Graphics-GUI/AffineTransformdemo.htm

Author

Commented:
>>You might be lucky in not perceiving too much difference, but the image WILL be degraded due to >>interpolation. Why not just start out with the correct size of your choice?


actually i could understood you clearly, "Why not just start out with the correct size of your choice?"
can i give the size of icon ?
Could you please explain ?
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I have to display icon view of  all the file, contained in a specific folder on MAC OS X java . This folder may contain any kind of file , for example it can be pdf file or jpg, or a email or rtf and so on. As i can not ensure the folder will contain which type of file ,so i thought it would be better to get the icon/image of the file based on the file type  from the os. And for this i can use JFileChooser that return the icon of requested file type. But it returns the icon of 16 * 16 size. But i need in 128 *128 ??
Awarded 2011
Awarded 2011

Commented:
I'm not sure, but I was under the impression thet those icons are raster files.
If so, you cannot hope to scale them up without losing quality.
If they were vector graphics, then you can scale up those as much as you want,
but with raster, I don't think it is possible to do it without losing quality.

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
either scale the image or provide your own images as required
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.