Sunday, April 19, 2009

An Easy way of adding background images for JFrames/JDialogs

People who are working with Java JFrames using NetBeans IDE may have experienced that adding a background image for a Jframe is not a very easy thing (have to write some codes).
I found a cool and easy way of doing that.

Here’s what you can do

1.Choose null layout as the layout for the frame.
2.Add your all components and arrange them.
3.Add a Label and delete the label text.
4.Resize the label into full frame size
5.Get the properties window of the Label and select icon.
6.Select your background image for the icon property of the label

That’s all. Very simple.

If you want to add a component after setting the background, you can send the background (Label) behind the other components using option of the JFrame.