Java 在JCheckBox中自定义“框”

Java 在JCheckBox中自定义“框”,java,swing,jcheckbox,Java,Swing,Jcheckbox,我想改变JCheckBox内的框的外观。我试图创建一个CustomIcon类来实现Icon,并使用方法JCheckBox.setDisabledIcon和JCheckBox.setDisabledSelectedIcon在我的类中设置图标,但没有得到任何结果。这是我在试图@Override BasicCheckBoxUI.paint方法之后找到的最好的解决方案,但它也不起作用 自定义图标类: 利用率: 你能帮我找到错误,或者解释一下怎么做吗?我将setDisabledSelectedIcon更改

我想改变JCheckBox内的框的外观。我试图创建一个CustomIcon类来实现Icon,并使用方法JCheckBox.setDisabledIcon和JCheckBox.setDisabledSelectedIcon在我的类中设置图标,但没有得到任何结果。这是我在试图@Override BasicCheckBoxUI.paint方法之后找到的最好的解决方案,但它也不起作用

自定义图标类:

利用率:


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

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

{
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)));