在 GUI 中将图像添加到 JPanel
Adding image to JPanel in GUI
它说构造函数 JPanel(ImageIcon) 未定义。
这是我的部分代码
public Method_1(Test aa) {
this.aa = aa;
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 730, 540);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
//JPanel panel = new JPanel();
BufferedImage myPicture = ImageIO.read(new File("method_1.png"));
JPanel picLabel = new JPanel(new ImageIcon(myPicture));
add(picLabel);
picLabel.setBounds(12, 34, 369, 175);
变化:
JPanel picLabel = new JPanel(new ImageIcon(myPicture));
收件人:
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
它说构造函数 JPanel(ImageIcon) 未定义。
这是我的部分代码
public Method_1(Test aa) {
this.aa = aa;
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 730, 540);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
//JPanel panel = new JPanel();
BufferedImage myPicture = ImageIO.read(new File("method_1.png"));
JPanel picLabel = new JPanel(new ImageIcon(myPicture));
add(picLabel);
picLabel.setBounds(12, 34, 369, 175);
变化:
JPanel picLabel = new JPanel(new ImageIcon(myPicture));
收件人:
JLabel picLabel = new JLabel(new ImageIcon(myPicture));