Smartclient resize listener

Does anyone know of a possibility to add a listener in order to dynamicaly handle resizing of the smart client?

What we actually want to do is equally tile/resize 16 small tabpanels in 1 form.
Anchoring can’t be used as it will create overlap, so I was thinking of adding this listener to call a ‘resize’ method when the smart client gets resized.

Thnkx for any input!

That is going to be quite a job marc :)

What you might be able to do (not sure if Servoy ‘allows’ you to use it though) is attach a java component listener to the window and listen to the resize event.

Maybe this will get you started: http://java.sun.com/docs/books/tutorial … tener.html

Hi Marc,

I actually have filed this as a feature request: #175965 “onWindowResize (form) event”
Status is still set as ‘New’.

But yeah, if we can do it with a method (and java) that would be great.

ROCLASI:
I actually have filed this as a feature request: #175965 “onWindowResize (form) event”
Status is still set as ‘New’.

But yeah, if we can do it with a method (and java) that would be great.

Hi Robert,

in the meantime, you can use this (works in 4.1.1 - developer and smart client - not web client):

// a form variable to test our listener:
var frmSize = null;

function resizeListener()
{
	/**
	 * Listener callback function (called by the Servoy's frame when it is resized)
	 */
	
	// The only argument is a java.awt.event.ComponentEvent:
	var e = arguments[0];
	if (e) {
		// get the component that fired this event (our frame):
		var frm = e.getComponent();
		// do whatever we need with its properties, here we set our variable to the frame size:
		frmSize = ""+frm.getWidth()+"x"+frm.getHeight();
	}
}

function onLoad_setFrameListener()
{
	/**
	 * This function initializes and sets the frame component listener
	 * it should only be called once (typically on an onLoad event)
	 */

	// first, get a list of all frames:
	var frames = Packages.java.awt.Frame.getFrames();
	// then get the top most frame: first in the array
	var frm = frames[0];
	
	/*
	 * Next is a workaround to avoid adding the same listener more than once
	 * this is necessary in developer when you stop and start the solution again
	 * to avoid having the listener being fired more than once
	 * 
	 * NB: it might be dangerous if Servoy itself is registering a listener
	 * From my tests, it is not the case yet
	*/
	
	// get a list of all previous listeners
	var listeners = frm.getComponentListeners();
	// remove them
	for(i=0; i < listeners.length; i++) {
		var tmp = listeners[i];
		frm.removeComponentListener(tmp);
	}

	// now create an object implementing the ComponentListener interface (thanks to Rhino):
	// we can pass a function name to any event, here we pass 
	// our resizeListener function
	var frmListener = new Packages.java.awt.event.ComponentListener({ 
		componentMoved: {}, 
		componentHidden: {}, 
		componentResized: resizeListener, 
		componentShown: {}
	});
	
	// now add the component listener to the Servoy's frame:
	frm.addComponentListener(frmListener);
	// while we have the frame reference, get its size and assign to our variable:
	frmSize = ""+frm.getWidth()+"x"+frm.getHeight();
}

To test, paste in a form’s script, assign the onLoad event to the “onLoad_setFrameListener”, and put a field on your form pointing to the “frmSize” form variable…

Enjoy!

Hi Ptalbot,

Quick test shows that this does exactly what I want :D
Thank you !

Thanks to all for the input!

@ptalbot: I think Robert tested it already, so I will go ahead and implement this pretty soon as well!

Thank you very for this very useful tip

With Servoy 5 we can now use anchoring in webclient
How can i have a the same kind of listener ?