Drawing an Image to a JPanel within a JFrame

后端 未结 3 736
忘了有多久
忘了有多久 2020-12-09 21:21

I am designing a program that contains two JPanels within a JFrame, one is for holding an image, the other for holding GUI components(Searchfields etc). I am wondering how d

3条回答
  •  没有蜡笔的小新
    2020-12-09 21:45

    I'd like to suggest a more simple way,

      image = ImageIO.read(new File(path));
      JLabel picLabel = new JLabel(new ImageIcon(image));
    

    Yayy! Now your image is a swing component ! add it to a frame or panel or anything like you usually do! Probably need a repainting too , like

      jpanel.add(picLabel);
      jpanel.repaint(); 
    

提交回复
热议问题