Home Java Example Java Swing Customize the Icon in a JCheckBox Component of Java Swing

Related Tutorials


 
 

Share on Google+Share on Google+

Customize the Icon in a JCheckBox Component of Java Swing

Advertisement
This section shows you how to customize the icon in a check box component.

Customize the Icon in a JCheckBox Component of Java Swing

     

This section shows you how to customize the icon in a check box component. That means any icon can be shown where the checked or unchecked box of the check box is situated. The specified icon is looked with the given text for the check box. Image for the pictorial representation is as follows: 

Customized Swing Check Box

Following is the method used in this program:

setIcon(Icon):
This is the method of the JCheckBox class which sets the icon in the check box component of swing. The icon is passed to the
setIcon() method as a parameter. The image for icon is specified in the ImageIcon() constructor of the ImageIcon class. This constructor has been used in this program to create the instance of the Icon class for specifying the image name.

Here is the code of the program:

import javax.swing.*;

public class CustomizedCheckBox{
  public static void main(String[] args){
  JFrame frame = new JFrame("Customized Check Box");
  Icon im = new ImageIcon("cut.gif");
  JCheckBox chk = new JCheckBox("This is the Customized Check Box");
  chk.setIcon(im);
  frame.add(chk);
  frame.setSize(400400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Discuss: Customize the Icon in a JCheckBox Component of Java Swing  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com