I'm doing a tutorial and would add a background image. I've tried to do this:
public void run() {
JFrame frame = new JFrame("VisLibDemo");
try{
frame.setContentPane(new JLabel( new ImageIcon(ImageIO.read(new File("C:/Users/RPR1BRG/Pictures/Brg800.jpg")))));
}catch(IOException e){
System.out.println("Error");
}
frame.setMinimumSize(new Dimension(500, 400));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new VisLibDemo());
frame.pack();
frame.setVisible(true);
}
However I am not getting.
Or not showing the background image, or when it appears is on top and the rest will not appear.
This is what I have:
And I wanted to add image to background...
I do this:
public void run() {
ImageIcon icon = new ImageIcon(
getClass().getResource("/Images/Brg800.jpg"));
JLabel label = new JLabel(icon);
label.setLayout(new BorderLayout());
JFrame frame = new JFrame("VisLibDemo");
//frame.add(new VisLibDemo());
frame.setContentPane(label);
VisLibDemo demo = new VisLibDemo();
demo.setOpaque(false); frame.add(demo);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
But I can only see a little bit of the background image ("/Images/Brg800.jpg")
Sorry for the bad explanation. But I need some help!
Can help me Please!!