0

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

  • 1
    Possible duplicate of [How to change the color of an icon based on user action?](http://stackoverflow.com/questions/8029903/how-to-change-the-color-of-an-icon-based-on-user-action) – mech Feb 18 '16 at 07:42
  • No it is not a duplicate of the post above. I want to coordinate my menu item's icon with the color that the user chooses –  Feb 18 '16 at 17:07
  • you can change the background of your JMenuItem by simply setting its background color, eg. myColorItem.setBackground(color); – Muhammad Feb 18 '16 at 17:44
  • yes i understand that but I only want an icon ( sort of ,perhaps a small square ) on the left side of "Color..." to show the currently selected color. –  Feb 18 '16 at 19:34

0 Answers0