Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在JLabel中调整图像/图标大小?_Java_Swing_Icons_Jlabel - Fatal编程技术网

Java 如何在JLabel中调整图像/图标大小?

Java 如何在JLabel中调整图像/图标大小?,java,swing,icons,jlabel,Java,Swing,Icons,Jlabel,这是我的密码: 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); 现在,从图标中提取的图像非常小。如何调整大

这是我的密码:

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);
现在,从图标中提取的图像非常小。如何调整大小?

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)));
    }
}
例如,见。但是一旦你的图标变大了,它可能会很难看。另请参阅这篇相关文章。