-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
  • 197,959
  • 33
  • 457
  • 689

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,160
  • 3
  • 17
  • 30
Rajan Kali
  • 11,436
  • 3
  • 24
  • 35
  • 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