Traditionally the background color of JLable is transparent, we can change it by using following code:
1
2
3
4
5
6
|
JPanel panel = new JPanel(); JLabel label = new JLabel( "JLabel Demo" ); label.setOpaque( true ); label.setForeground(Color.blue); label.setBackground(Color.lightGray); panel .add(label); |
Code label.setOpaque(true)
is required to paint the background color of JLabel.