0

I'm having some problems with my Java interface, where I'm trying to put a background image on my JFrame.
I searched on the internet and I found a 3 lines of code that work (it prints the image), but the problem is that the image stays above all the rest and wides the text, at least that's what I think is happening!

Here is the code I'm using to print the image:

setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("lock.jpg")));
setLayout(new FlowLayout());

Can someone explain what or why this is happening and give any solution?

dee-see
  • 23,668
  • 5
  • 58
  • 91
  • you have more then one option. 1.You can override paint method and paint with graphic object.2. You can use Layered pane bud that might be problematic if you use some sort of layout – Tomas Bisciak Jan 04 '14 at 01:16
  • @TomasBisciak - I wouldn't say it's the exact duplicate, but OP would definitely benefit from reading the answers. – PM 77-1 Jan 04 '14 at 01:43

1 Answers1

0

I would suggest declaring your JLabel somewhere else, then calling getGraphics() on it and then using that Graphics object to first draw an image and then a string.

Epiglottal Axolotl
  • 1,048
  • 8
  • 17