# Repaint Objects when Component is resized

**URL:** <https://forum.inductiveautomation.com/t/repaint-objects-when-component-is-resized/5644>\
**Category:** Module Development\
**Created:** [January 4, 2013, 11:11am UTC](https://forum.inductiveautomation.com/t/repaint-objects-when-component-is-resized/5644 "2013-01-04T11:11:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GermainN](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@GermainN](https://forum.inductiveautomation.com/u/GermainN)\
**Post date:** [January 4, 2013, 11:11am UTC](https://forum.inductiveautomation.com/t/repaint-objects-when-component-is-resized/5644/1 "2013-01-04T11:11:21Z")

</div>

Hi all and a happy new year to all developpers 😉

I’m making a Chart based on AbstractVisionComponent for Client/Designer.  
I just want to make the Chart getting the whole space of the component.  
I use the getWidth and getHeigth methods of the AbstractVisionComponent, but I can’t get the event.

Can anyone help ?  
Do I have to make a ChangeListener for these properties ?  
 ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

Thanks for help.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [January 4, 2013, 2:22pm UTC](https://forum.inductiveautomation.com/t/repaint-objects-when-component-is-resized/5644/2 "2013-01-04T14:22:36Z")

</div>

I’ve use the following code in an AbstractVisionComponent which contains other components, to resize the sub-components according to the main :

```auto
	import java.awt.event.ComponentListener;
	
	Add to the constructor :
	
	ComponentEventListener cl = new ComponentEventListener();
	this.addComponentListener(cl);
	
	Add this subclasse in the class which extends AbstractVisionComponent :
	
	public class ComponentEventListener implements ComponentListener {
		public void componentHidden(ComponentEvent e) {
		}

		public void componentMoved(ComponentEvent e) {
		}

		public void componentResized(ComponentEvent e) {
		
			// resize your subcomponent here...
			canvas.setSize(getWidth(), getHeight());
			panel.setSize(getWidth(), getHeight());
		}

		public void componentShown(ComponentEvent e) {
		}
	}
```

hope this helps !

---

<div class="post-metadata">

**Author:** ![GermainN](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@GermainN](https://forum.inductiveautomation.com/u/GermainN)\
**Post date:** [January 4, 2013, 2:26pm UTC](https://forum.inductiveautomation.com/t/repaint-objects-when-component-is-resized/5644/3 "2013-01-04T14:26:56Z")

</div>

Exactly what I needed !  
Oh yes it helps 😆

I’ll try it as soon as possible.  
Thanks !
