-2

I want to set an icon for a jlabel, can somebody give me example syntax

I have tried this :

JLabel icon = new JLabel();
ImageIcon chromo = createImageIcon("res/icon.png");
panel.add(icon);
icon.setIcon(chromo);

After I tried this the label didn't show up on the panel at all.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720

1 Answers1

-1

Try this:

JLabel icon = new JLabel();
ImageIcon chromo = createImageIcon("res/icon.png");
icon.setIcon(chromo);
panel.add(icon);

And don't forget to check your layout, if it is absolute then you need to add bounds to it.

icon.setBounds(startX, startY, width, height);
Skully
  • 2,882
  • 3
  • 20
  • 31
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
  • 3
    _if its Absolute you need to add bounds_ Nah, if it is absolute, you need to switch to a `LayoutManager` – Robin Oct 18 '14 at 08:57