我想用JLabel+ImageIcon来实现类似windows中幻灯片和缩略图的功能。
但是我不能控制Picture的尺寸大小。
愿那位高人指点一二
不胜感谢

解决方案 »

  1.   

    用 java.awt.Graphics 在 JPanel中画出图形吧,这样便于控制图形的大小。//这里提供了所要描绘图形的大小参数设置。
    drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
      

  2.   

    import java.awt.*;
    import java.awt.geom.AffineTransform;import javax.swing.*;public class ZoomIcon
    implements Icon
    {
    private Icon realIcon = null;
    private float scale = 1;

    public ZoomIcon(Icon icon, float scale)
    {
    realIcon = icon;
    this.scale = scale;
    } public void paintIcon(Component c, Graphics g, int x, int y)
    {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform oldTransform = g2d.getTransform();

    g2d.translate(x, y);
    g2d.scale(scale, scale);
    realIcon.paintIcon(c, g2d, 0, 0);

    g2d.setTransform(oldTransform);
    } public int getIconWidth()
    {
    return (int) (realIcon.getIconWidth() * scale);
    } public int getIconHeight()
    {
    return (int) (realIcon.getIconHeight() * scale);
    } public static void main(String[] args)
    {
    JLabel label = new JLabel();
    label.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    ImageIcon imgIcon = new ImageIcon(ZoomIcon.class.getResource("test.jpg"));
    Icon zoomIcon = new ZoomIcon(imgIcon, 0.9f);
    label.setIcon(zoomIcon);

    JFrame f = new JFrame();
    JPanel p = new JPanel();
    p.add(label);
    f.getContentPane().add(p, BorderLayout.CENTER);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

    }
    }
      

  3.   

    gtlang78() 的示例可能是我需要的,因为明后两天有点事,所以周日才能确认是不是我所需要的解答,在这里先谢谢gtlang78() 的帮助
      

  4.   

    谢谢。我也需要这个资料!
    Gueber() .能不能加你qq!
    372106576