我当前的代码不是从ImageIcon目录中拾取图像。我100%确定给定的路径是正确的,我不太确定这是什么问题。感谢您的回复。
private JFrame frame;
private JPanel panel;
private JLabel label2;
private JButton button;
private ImageIcon icon;
public void window() {
frame = new JFrame();
frame.setVisible(true);
frame.setSize(1300, 800);
frame.setAlwaysOnTop(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("GUI frame");
panel = new JPanel();
panel.setBackground(Color.cyan);
panel.setLayout(null);
frame.add(panel);
icon = new ImageIcon("C:/Users/user/image.jpg");
label2 = new JLabel(icon);
panel.add(label2);
}
}