[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to scale an icon returned by JFileChooser.get

Posted on 2011-04-22
14
Medium Priority
?
356 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.
0
Comment
Question by:Computer07
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35446723
Why not just use your own icon?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35446731
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35446734
btw, in most cases, you can never scale up without loss of image quality. Much better to start out with the correct size
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Computer07
ID: 35448309
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35448322
>> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35448343
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
 

Author Comment

by:Computer07
ID: 35448431
Can any body provide me the exact solution for this????
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35448481
If you're determined to scale it up, use an AffineTransform:

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

Author Comment

by:Computer07
ID: 35449687
>>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
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 35449781
I mean why don't you use your own icon in the first place?
0
 

Author Comment

by:Computer07
ID: 35453280
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
 
LVL 47

Expert Comment

by:for_yan
ID: 35453291
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
 
LVL 92

Expert Comment

by:objects
ID: 35464152
either scale the image or provide your own images as required
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35467744
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question