Below code will show you how to set Background color for a JLabel . JLabel class is used to create JLabel objects which have several metho...
Below code will show you how to set Background color for a JLabel .JLabel class is used to create JLabel objects which have several methods .Execute below code
/**
*
* @author Eric
* Blog:www.techoverload.net
*
*/
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JFrame;
public class JLabelExample extends JFrame{
JLabelExample()
{
super("JLabel Example");
JLabel label=new JLabel("JLabel Example");
label.setOpaque(true);
//code to set foreground color
label.setBackground(Color.BLACK);
//--------------------------------
label.setForeground(Color.WHITE);
label.setBounds(10,10,200, 20);
add(label);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setVisible(true);
}
public static void main(String args[])
{
new JLabelExample();
}
}