JLabel is a display area for a short text string or an image, or both, it is a basic GUI Component defined in Java Swing library. A label does not react to input events. As a result, it cannot get the keyboard focus. In this how-to, we will go over how to set appearance: JLabel font size and color.

Example Source Code to set JLabel font size

JLabel jUserName = new JLabel("Demo How to Set JLabel font size");
jUserName.setFont(new Font("Serif", Font.BOLD, 11));
JFrame frame = new JFrame("Demo Window");

Set JLabel foreground color

JLabel jUserName = new JLabel("Demo foreground ");

Set JLabel background color
By default, the background of JLabel is transparent, so you can not directly set backgroud for a jlabel component. Instead of, add A JLabel to JPanel and set background for the JPanel.

JLabel jUserName = new JLabel("Demo background");
JPanel titlePanel = new JPanel();