在 JCheckBox 中自定义 "Box"

Customizing the "Box" in a JCheckBox

我想更改 JCheckBoxBox 的外观。我试图创建一个 "CustomIcon" class 其中 implemenst "Icon",并且,使用方法"JCheckBox.setDisabledIcon()""JCHeckBox.setDisabledSelectedIcon()" 用我的 class 设置图标,但我没有得到任何结果。这是我在尝试 @Override "BasicCheckBoxUI.paint()" 方法后找到的最佳解决方案,而且也没用。

CustomIcon class:

{
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Ionut Cicio
 */
public class CustomizedIcon implements Icon{
    public int width;
    public int height;

    public Color color;

    public CustomizedIcon(int width, int height, Color color){
        this.width = width;
        this.height = height;
        this.color = color;
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y){
        g.setColor(this.color);
        g.fillRect(x, y, width, height);

        g.drawRect(x, y, width, height);
    } 

    @Override
    public int getIconWidth(){
        return this.width;
    }

    @Override
    public int getIconHeight(){
        return this.height;
    }
}

利用率:

    rememberPasswordCheckBox.setDisabledSelectedIcon(new CustomizedIcon(10, 10, new Color(100, 255, 100)));
    rememberPasswordCheckBox.setDisabledIcon(new CustomizedIcon(10, 10, new Color(255, 100, 100)));

你能帮我找出错误,或者解释一下怎么做吗?

我将 setDisabledSelectedIcon 更改为 setSelectedIcon,将 setDisabledIcon 更改为 setIcon,它工作正常 - 即使是禁用的复选框。