JLabel of visual bug when using setBackground ()

0

When I use JLabel.setBackground(Color); it simply gives a visual bug.

Layout:

    quarto1 = new JPanel();
    quarto1.setBounds(10, 11, 158, 82);
    frame.getContentPane().add(quarto1);
    quarto1.setLayout(null);

    JButton novoB = new JButton("");
    novoB.setIcon(new ImageIcon(layout.class.getResource("/imagens/novo.png")));
    novoB.setBorderPainted(false);
    novoB.setBounds(10, 48, 30, 30);
    quarto1.add(novoB);

    JButton editarB = new JButton("");
    editarB.setIcon(new ImageIcon(layout.class.getResource("/imagens/editar.png")));
    editarB.setBorderPainted(false);
    editarB.setBounds(118, 48, 30, 30);
    quarto1.add(editarB);

    frame.repaint();

Code:

insira o código aquistatic Color ocupado = new Color(252, 36, 36, 140);
static Color livre = new Color(70, 250, 34, 140);
static Color sujo = new Color(251, 117, 9, 140);

public static void setRoomState(JPanel quarto, Color state)
{
    quarto.setBackground(state);
    System.out.println(quarto.getComponent(1).getName().toString());
}

Bug:

    
asked by anonymous 11.08.2016 / 21:15

1 answer

1

To paint Swing components, they must be marked as opaque (non-transparent). Did you confirm that JPanel is marked as opaque?

jPanel.setOpaque(true);
    
11.08.2016 / 22:10