CustomButton cannot be converted to JButton

56 Views Asked by At

I want to customize a button as the code shows below

public class CustomButton extends JToggleButton{

    public CustomButton() {
    }
  
    public void paintComponent(Graphics g){
        Color bg,text;
        if(isSelected()){
            bg = Color.decode("#000");
            text = Color.decode("#fff");
        }else{
            bg = Color.decode("#fff");
            text = Color.decode("#000"); 
        }
        setBackground(bg);
        setForeground(text);
        super.paintComponent(g);
    }
}

I got this error =>

Incompatible types : CustomButton cannot be converted to jButton

jButton2 = new CustomButton();

Can you tell where is the problem?

0

There are 0 best solutions below