Java JLabel set background color

Description

Java JLabel set background color

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame {

  public Main() {
    super("Link JLabel with JTextField");

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel nameLabel = new JLabel("Java demo from demo2s.com.");
    Color customColor = new Color(255,10,255);
    nameLabel.setOpaque(true);//w w w . j ava  2s.co  m
    nameLabel.setBackground(customColor);

    add(nameLabel);

  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related