0

I have a project in which I have added an image throuh JLabel which is my background image. Now I want to add a transparent image through JLabel image which has got some text over it. When I am adding my image over the background image it is disappearing. How to achieve it?

Here is the code of 2 labels lmain is the name of background image label and lblNewLabel is the name of the text image label.

JLabel lmain = new JLabel("");
lmain.setBounds(0, 0, 1600, 900);
pmain.add(lmian);
lmain.setIcon(new ImageIcon("C:\\Users\\Raabii Ansari\\Desktop\\k3.jpg"));

JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setBounds(502, 69, 498, 232);
lmain.add(lblNewLabel);
lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Raabii Ansari\\Desktop\\text (4).gif"));
Marko
  • 20,385
  • 13
  • 48
  • 64
cute programmer
  • 27
  • 1
  • 11
  • 1
    Well, `JLabel` is just a `Container`, you could just add one label into another, possibly even using a layout manager, something like [this](http://stackoverflow.com/questions/33115320/having-a-jlabel-on-top-of-another-jlabel-that-has-an-image/33115415#33115415) for example. Not my preferred method, but it will generally work – MadProgrammer Oct 14 '15 at 10:10
  • 1
    See also this [related approach](http://stackoverflow.com/a/2658663/230513). – trashgod Oct 14 '15 at 11:22

0 Answers0