0

I am making a very basic GUI in java swing, but when i try to use a picture as a label, the picture doesn't show up.

The picture is an .jpg file and is located in the src folder in the project. also, the GUI part fo the code is NOT in the main method, but in another class.

here's the code:

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Color;

public class GUI extends JFrame {

    GUI () {
        // Create a JFrame and setting stuff up
        this.setSize(1500,700);
        this.setResizable(true);
        this.setTitle("example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        ImageIcon Label1_Pic = new ImageIcon(pic.jpg);

        JLabel Label1 = new JLabel();
        Label1.setIcon(Label1_Pic);

        this.getContentPane().setBackground(new Color(255, 255, 255));
        this.add(Label1);
   }
}

After 2 hours of google-ing, I ended up asking here. Thanks a lot for the help

0 Answers0