出现,这是我的代码:图像不会在JFrame的
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class SenzuView extends JFrame {
JLabel label;
public SenzuView(){
ImageIcon image = new ImageIcon("C:\\senzu.jpg");
label = new JLabel("", image, JLabel.CENTER);
this.add(label);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);
}
public static void main(String[] args) {
new SenzuView();
}
}
的问题是,该框架将打开,但其空和图像不会出现在提前 感谢
您确定该文件存在吗?代码在运行时显示图片。 – Breeze
您可能需要将标签添加到'BorderLayout.CENTER',以便它自动调整大小。您可以查看JavaDoc以获取更多信息。 – AlBlue
我还建议使用'ImageIO.read'通过'ImageIcon'直接加载图像,请参阅[读取/加载图像](http://docs.oracle.com/javase/tutorial/2d/images /loadimage.html)了解更多详情 – MadProgrammer