Pages

Get default JLabel background color

Complete source code below will show you, how to get default JLabel background color and after that, it will print RED,GREEN,BLUE(RGB) value for the color.

*****************************************************************
COMPLETE SOURCE CODE FOR : GetDefaultJLabelBackgroundColor.java
*****************************************************************


import javax.swing.JLabel;

import java.awt.Color;

public class GetDefaultJLabelBackgroundColor
{
public static void main(String[]args)
{
//Create a label using JLabel
JLabel label=new JLabel();

//Get label background color using method getBackground()
Color labelBackgroundColor=label.getBackground();

//Get RED value from color
int redValue=labelBackgroundColor.getRed();

//Get GREEN value from color
int greenValue=labelBackgroundColor.getGreen();

//Get BLUE value from color
int blueValue=labelBackgroundColor.getBlue();

//Print RGB value that we get
System.out.println("R : "+redValue);
System.out.println("G : "+greenValue);
System.out.println("B : "+blueValue);

//You can check what color that match the RGB value that we get using 'Color picker' at above
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************
Related Posts Plugin for WordPress, Blogger...