JLabel label = new JLabel("Hello World"); label.setBackground(Color.RED);
JLabel label = new JLabel(); label.setIcon(new ImageIcon("image.png")); label.setBackground(Color.WHITE);In this example, a JLabel component is created without any text. The setIcon method is used to set an image on the label. The setBackground method is used to set the background color of the label to white. These examples belong to the javax.swing package library, which is a part of the Java standard library.