• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

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.
0
Computer07
Asked:
Computer07
  • 7
  • 4
  • 2
  • +1
1 Solution
 
CEHJCommented:
Why not just use your own icon?
0
 
for_yanCommented:
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
0
 
CEHJCommented:
btw, in most cases, you can never scale up without loss of image quality. Much better to start out with the correct size
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

http://www.java2s.com/Code/Java/2D-Graphics-GUI/AffineTransformdemo.htm
0
 
Computer07Author 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 ?
0
 
CEHJCommented:
I mean why don't you use your own icon in the first place?
0
 
Computer07Author 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 ??
0
 
for_yanCommented:
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.

0
 
objectsCommented:
either scale the image or provide your own images as required
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now