Add Icon to a JCheckBox in Java
Description
The following code shows how to add Icon to a JCheckBox.
Example
import java.awt.FlowLayout;
/* w ww.ja va2 s .com*/
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("JCheckBox Test");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox ac = new JCheckBox("A/C");
Icon rollIcon = new ImageIcon("a.gif");
ac.setRolloverIcon(rollIcon);
frame.add(ac);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »