Link to home
Start Free TrialLog in
Avatar of Computer07
Computer07

asked on

How to scale an icon returned by JFileChooser.get


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.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not just use your own icon?
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
btw, in most cases, you can never scale up without loss of image quality. Much better to start out with the correct size
Avatar of Computer07
Computer07

ASKER

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.
>> 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)
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?
Can any body provide me the exact solution for this????
If you're determined to scale it up, use an AffineTransform:

http://www.java2s.com/Code/Java/2D-Graphics-GUI/AffineTransformdemo.htm
>>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 ?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ??
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.

either scale the image or provide your own images as required
:)