Skip to main content

Posts

Showing posts from July 22, 2011

JColorComboBox: JComboBox as Color Chooser

  Swing toolkit provides a component called JColorChooser to choose colors. It allows users to select color from multiple color combinations. Some times our application may need simple component with an option to select only basic colors/ less number of color options unlike sepearate dialog with too may color options[JColorChooser]. This JColorComboBox may serve the need. I wanted my color chooser to behave like JComboBox. The popup shows all 12 colors and their names, among all of them one color can be choosen. see the below image. I created two classes          1. JColorComboBox          2. ColorRenderer JColorComboBox extends the JComboBox and ColorRenderer extends JLabel and implements ListCellRenderer. import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.util.Enumeration; import java.util.Hashtable; import javax.swing.*; /** * * @author sharath */ public class JCol...