Try this:
icon.paintIcon(new JCheckBox(), image.getGraphics(), 0, 0);
I can't exactly explain why it needs a JCheckBox
though. Perhaps it varies for the icon? The NullPointerException
was from this line in MetalIconFactory
for "CheckBox.icon"
:
ButtonModel model = ((JCheckBox)c).getModel();