# Bounds2DComponent bounding box listener

**URL:** <https://forum.inductiveautomation.com/t/bounds2dcomponent-bounding-box-listener/84835>\
**Category:** Module Development\
**Created:** [January 26, 2024, 8:47pm UTC](https://forum.inductiveautomation.com/t/bounds2dcomponent-bounding-box-listener/84835 "2024-01-26T20:47:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 26, 2024, 8:47pm UTC](https://forum.inductiveautomation.com/t/bounds2dcomponent-bounding-box-listener/84835/1 "2024-01-26T20:47:18Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 29, 2024, 7:10pm UTC](https://forum.inductiveautomation.com/t/bounds2dcomponent-bounding-box-listener/84835/2 "2024-01-29T19:10:21Z")

</div>

I ended up putting the following code under the `paintComponent` method.  
`paintArea` is a global variable.

```auto
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;
        }

```
