-2

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 ?

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
  • Downvoters, would you mind explaining ? I looked thoroughly on the web and stackoverflow before posting this question, didn't find anything, and it seems this could be some reusable knowledge. – Vic Seedoubleyew Feb 10 '17 at 22:09

1 Answers1

1
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.

Community
  • 1
  • 1
Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76