Java Swing Tutorial - Java Color.darker()








Syntax

Color.darker() has the following syntax.

public Color darker()

Example

In the following code shows how to use Color.darker() method.

//ww w.  j  a  v  a 2 s  .c  om
import java.awt.Color;

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

public class Main {
  public static void main(String[] args) {
    Color myColor = Color.RED;          

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

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

    
  }
}