Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Set JCheckBox background color (Java)

Source code below will show you, how to set JCheckBox background color base on RGB. You can get RGB value for your color using "Color picker" at above.

*************************************************************
COMPLETE SOURCE CODE FOR : SetJCheckBoxBackgroundColor.java
*************************************************************
import javax.swing.JCheckBox;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJCheckBoxBackgroundColor
{
public static void main(String[]args)
{
 //Create check box with text HI using JCheckBox
 JCheckBox checkBox=new JCheckBox("HI");

 //Create JFrame with title ( Set JCheckBox background color )
 JFrame frame=new JFrame("Set JCheckBox background color");

 //Set JFrame layout to FlowLayout
 frame.setLayout(new FlowLayout());

 //Set color base on RGB
 //You can get RGB value for your color at "Color picker" at above
 //R=255
 //G=0
 //B=0
 Color color=new Color(255,0,0);

 //Set JCheckBox background color to color that you choose
 checkBox.setBackground(color);

 //Add JCheckBox into JFrame
 frame.add(checkBox);

 //Set default close operation for JFrame
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 //Set JFrame size
 frame.setSize(500,300);

 //Make JFrame visible
 frame.setVisible(true);
}
}


*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************