3

Here's my code:

String s = "/Applications/Asphalt6.app";
JFileChooser chooser = new JFileChooser();

File file = new File(s);
Icon icon = chooser.getIcon(file);

// show the icon
JLabel ficon = new JLabel(s, icon, SwingConstants.LEFT);

Now, the image extracted from the icon is really small. How can I resize it?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Tushar Chutani
  • 1,522
  • 5
  • 27
  • 57
  • 1
    See for example [this](http://www.javalobby.org/articles/ultimate-image/#11). But your icon will probably be quite ugly once it is made bigger. – toto2 Aug 26 '11 at 01:51

1 Answers1

7

Big Icon

import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;

class BigIcon {

    public static void main(String[] args) {
        JFileChooser chooser = new JFileChooser();
        File f = new File("BigIcon.java");
        Icon icon = chooser.getIcon(f);

        int scale = 4;

        BufferedImage bi = new BufferedImage(
            scale*icon.getIconWidth(),
            scale*icon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bi.createGraphics();
        g.scale(scale,scale);
        icon.paintIcon(null,g,0,0);
        g.dispose();

        JOptionPane.showMessageDialog(
            null,
            new JLabel(new ImageIcon(bi)));
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    See also this related [example](http://stackoverflow.com/questions/2900801/wanting-a-type-of-grid-for-a-pixel-editor/2901472#2901472). – trashgod Aug 26 '11 at 02:10