How to crop an Icon object in Java, for use within the Java Swing framework ?
Say you get an Icon, and you would like to use it in a JButton
, but it is too big. How do you crop it ?
How to crop an Icon object in Java, for use within the Java Swing framework ?
Say you get an Icon, and you would like to use it in a JButton
, but it is too big. How do you crop it ?
Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(
iconToImage(icon).getSource(),
new CropImageFilter(leftX, topY, width, height)
)
);
See here to implement the iconToImage
method to convert your icon to an image.