Honestly there should be a way to do this in one step using the RectanglePlacement flags, but I can never figure it out without trial and error:
What is the opposite to RectanglePlacement::fillDestination i.e. letterboxed, maximum size without cropping while keeping the aspect ratio?
If possible it would be great to have an alias, like RectanglePlacement::centred is an alias.
IIUC you need the setBounds to control the drawables paint() method, while for the draw() you might not need it.
But in the past I had often unexpected results because of this duality between Drawable and Component. Seems the setBoundsToFit and other methods that modify the transformation moves the result out of the setBounds() area. I know that is to be expected, but I didn’t understand how it is used in a controlled manner (and unusally I have no trouble understanding matrices and transformations).
This is the second reason why I filed this feature request, feel free to support it here: