How to set background image in Java for a JFrame using a JLabel

How to set background image in Java for a JFrame using a JLabel


__________________________________________________________________________

In This Java Code We Will See How You Can Make A BackGround Image For Your JFrame In Java Using A JLabel Programming Language.

Project Source Code:

package learn;
import java.awt.FlowLayout;
import javax.swing.*;
import java.io.IOException;
import java.io.*;
import javax.imageio.*;

public class Test extends JFrame{
 
    public Test(){
    super("window");
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try{
        setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\Users\\samsng\\Documents\\NetBeansProjects\\images\\image.jpg")))));
 
    }catch(IOException e)
    {
        e.printStackTrace();
     
    }
    this.setLayout(new FlowLayout());
    this.setResizable(false);
    this.pack();
    this.setVisible(true);
    }

public static void main(String[] args) {

       Test t = new Test();

    }
}




Share this

Related Posts

Previous
Next Post »