ROCLASI wrote: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):
- Code: Select all
// 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!