我试图简单地将照片加载到 jpanel 但它不起作用。
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.*;
public class ImageTest3 extends JFrame {
public ImageTest3() {
// TODO Auto-generated constructor stub
JPanel panel = new JPanel(new FlowLayout());
Icon icon = new ImageIcon(
File.separator + "resources"
+ File.separator + "images"
+ File.separator + "topbar.jpg");
JLabel label1 = new JLabel();
panel.add(label1);
add(panel);
label1.setIcon(icon);
setSize(2000,700);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new ImageTest3();
}
}
对不起,糟糕的表格......文件保存在我的\src\resources\images\topbar.jpg
我究竟做错了什么 ?我也有它作为ImageIcon icon = new ImageIcon
....