0

Why isn't the background of this image showing up red even when all the other set commands work?

JPanel jp =new JPanel();
JLabel jl =new JLabel();
public Trial1()
{
    jp.setOpaque(false);
    jp.setBackground(Color.ORANGE);

    setTitle("name");
    setVisible(true);
    setSize(600,600);
    setLocationRelativeTo(null);
    setResizable(false);
    setDefaultCloseOperation(EXIT_ON_CLOSE);


//finding and adding image      

    jl.setIcon(new ImageIcon("location"));
    jp.add(jl);
    add(jp);
    validate();
  • Perhaps your JPanel needs to be transparent? Based off [this user Stefan](http://stackoverflow.com/questions/10148421/jpanel-setbackgroundcolor-black-does-nothing) – Matthew Doran Jun 08 '16 at 02:11

1 Answers1

0

Your JFrame's content pane is covered by the jp JPanel. Set it non-opaque:

jp.setOpaque(false);
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373