Java Swing Tutorial - Java Color(float r, float g, float b, float a) Constructor








Syntax

Color(float r, float g, float b, float a) constructor from Color has the following syntax.

public Color(float r,  float g,  float b,  float a)

Example

In the following code shows how to use Color.Color(float r, float g, float b, float a) constructor.

import java.awt.Color;
//from   ww w. ja  v a  2 s .  c  o m
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
  public static void main(String[] args) {
    Color myBlack = new Color(0,0,0,0.5F);           // Color black
//  Color myWhite = new Color(255,255,255);     // Color white
//  Color myGreen = new Color(0,200,0);         // A shade of green

    JLabel label = new JLabel("First Name");
    label.setForeground(myBlack);

    JFrame frame = new JFrame();
    frame.add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20,20, 500,500);
    frame.setVisible(true);

    
  }
}