How do I set a menuItem's icon to the current JColorChooser color?

216 Views Asked by At

I want to set my myColorItem menu item to the color a user selects from my JColorChooser. I tried this but apparently i can not cast a color to an ImageIcon.

myColorItem = new JMenuItem("Color...");

    myColorItem.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent theEvent) {
            Color color = JColorChooser.showDialog(null, "", myDefaultColor);


       // This is what is not working 
            myColorItem.setIcon(new ImageIcon(color));
        }
    });

Thanks for any feedback

0

There are 0 best solutions below