I have a component that implements Bounds2DComponent
so that I can have control over the bounding rectangle. The Bounds2DComponent
interface causes the swing bounds to be the same as the parent. Because of the swing bounds being forced to the parent's bounds, I cannot use ComponentListener
to be notified when the component's size changes.
Is there a way to be notified of changes to the bounding rectangle of a component that implements Bounds2DComponent
?
I ended up putting the following code under the paintComponent
method.
paintArea
is a global variable.
boolean componentMoved = false;
boolean componentResized = true;
// Check to see whether the component has moved.
if ( !paintArea.getLocation().equals(getBoundingRect().getBounds().getLocation()) ) {
paintArea.setLocation(getBoundingRect().getBounds().getLocation());
componentMoved = true;
}
// Check to see whether the component has resized.
if ( !paintArea.getSize().equals(getBoundingRect().getBounds().getSize()) ) {
paintArea.setSize(getBoundingRect().getBounds().getSize());
componentResized = true;
}