主题:求助:如何设置JLabel中图片的大小
我写了一小段在JLabel中显示图片的代码,但是图片尺寸太大的话显示出来就会超过JFrame的范围了,请问怎么设置它来让它和 frame.setSize(500,500) 后的大小一样大呢
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class picDemo extends JFrame
{
private ImageIcon[] imageIcon= new ImageIcon[1];
private JLabel jlblImageViewer=new JLabel();
public static void main(String args[])
{
picDemo frame=new picDemo();
frame.setSize(500,500);//这里设置了窗口大小,我想让任何一张图片都和窗口一样大
frame.setVisible(true);
}
public picDemo()
{
super("Label Demo");
imageIcon[0]=new ImageIcon("1.jpg");
jlblImageViewer.setIcon(imageIcon[0]);
jlblImageViewer.setHorizontalAlignment(SwingConstants.CENTER);
add(jlblImageViewer,BorderLayout.CENTER);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class picDemo extends JFrame
{
private ImageIcon[] imageIcon= new ImageIcon[1];
private JLabel jlblImageViewer=new JLabel();
public static void main(String args[])
{
picDemo frame=new picDemo();
frame.setSize(500,500);//这里设置了窗口大小,我想让任何一张图片都和窗口一样大
frame.setVisible(true);
}
public picDemo()
{
super("Label Demo");
imageIcon[0]=new ImageIcon("1.jpg");
jlblImageViewer.setIcon(imageIcon[0]);
jlblImageViewer.setHorizontalAlignment(SwingConstants.CENTER);
add(jlblImageViewer,BorderLayout.CENTER);
}
}