Reputation: 399
I have a decorated JFrame
. I've added a background image to the frame and added a JButton
.
When I add a button the background image is not visible. What should I do?
Here is my code snippet.
public Demo3()
{
setTitle("STARTUP");
setSize(800,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true);
setLocationRelativeTo(null);
JPanel jp=new JPanel();
JButton jb=new JButton();
JLabel jl=new JLabel(new ImageIcon("c://image.jpg"));
jp.setLayout(null);
jp.add(jl);
jp.add(jb);
add(jp);
jb.setBounds(400,250,50,50);
setVisible(true);
}
Upvotes: 3
Views: 86
Reputation:
you need to set the layout of JLabel null.Then only setBounds method will work.
lj,setLaout(null);
jb.setBounds(400,250,50,50);
Upvotes: 0
Reputation: 324128
Don't use a null layout.
See Background Panel for a couple of options. Depending on your exact requirement you can:
Upvotes: 2