I have a JFileChooser that lets users choose an image for themselves. I want to limit the images they can choose to ones with square dimensions, for example –
width and height both 50
width and height both 75, etc…
So when they select an image with the JFileChooser and click ‘Open’ I need to validate the image size and if it doesn’t have square dimensions I need to present the user with a dialog informing them “The image must have the same width and height”.
I’m just learning swing so I don’t know how to do this. Any ideas on how to do this? Is there a way of hooking the “Open” button’s event handler?
You can hide all images that do not confirm to the rules with an implementation of a
FileFilter: