自定义的颜色图表, 下面的代码是个30*2的图标. import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; /** */ /** * 颜色图标 */ public class ColorIcon implements Icon ... { private Color color = Color.BLUE; private int iconHeight = 2; private int iconWidth = 30; public int getIconHeight() ...{ return iconHeight; } public int getIconWidth() ...{ return iconWidth; } public Color getColor() ...{ return color; } public void setColor(Color color) ...{ this.color = color; } public void paintIcon(Component c, Graphics g, int x, int y) ...{ g.setColor(color); g.fillRect(x, y, getIconWidth(), getIconHeight()); } /** *//** * 取得颜色的String值 * @return */ public String getColorString() ...{ String s = "#" + toHexString(color.getRed()) + toHexString(color.getGreen()) + toHexString(color.getBlue()); return s; } /** *//** * 将int转成16进制字符串 * * @param red * @return */ private String toHexString(int i) ...{ String s = Integer.toHexString(i); if (s.length() == 1) ...{ s += "0"; } return s; }}