View Full Version : How resize window to it's content sizes before show?

26 Jan 2011, 4:19 AM
Good day, megaprogers!
I wanna open Window with formpanel as it's content.
FormPanel may have dynamicall items (depending on user permission), so I don't know real width & height.
How should I set height & width of window to align it to form's size.

var formPanel = {
xtype : 'formpanel',
items : <someitems> - filled dynamically with 'lazy' objects
//width, height - calculates automatically by ExtJS

width : ?
height : ?
items : formPanel

For exmple, setting window height like 'autoHeight : true' or skipping it height parameter makes the window 0-sized.

28 Jan 2011, 3:42 AM
either set the layout config viewConfig: 'fit' or set the width / height programically before it is shown, by trapping the beforeshow event, something like the following:

aWindow.on("beforeshow", function (window) {
/* determine what the some Value is before setting it*/

} );

28 Jan 2011, 3:48 AM
your forms must be clearly defined. so, for each of them you must know exactly HOW you made it.
then, I think you must use a switch ... and set your window size according to your switch cases.
and if you cannot catch the beforeShow event (as ddudy says) then try to resize the window after show (of course if you use resize, then you can open it and show with no matter which values).
hope this can helps

28 Jan 2011, 3:57 AM
why cant you catch the beforeshow event is there a bug we are not aware of? my name is DDUFFY. Do not resize a window after it shows as this will be very poor UI experience. you do not need to know exactly how you made it, you do not need a switch, you can programatically define the width and height ased on the components on screen. or you could adjust the viewConfig and set to fit.

28 Jan 2011, 4:17 AM
hey ddufy. the switch he already have it somehow. if his window containts different forms depnds on config.
on THIS switch, he can get the forms size, and then apply it to window !!!

otherwise, generally speaking, if the forms are maded with some 'fit' correct parameters, or anchor '100% 100%' there is never need to resize nothing. The forrms will correctly fit into the window...

28 Jan 2011, 10:56 AM
Thank's for your replies. It seems to me the problem is really more complex, and depends not only on ExtJS.

or set the width / height programically before it is shown
Yes, I think this is the solution. I must calculate the sizes of FormPanel and then set them to Window.
First - I can't get them from FormPanel as form.getHeight() & getWidth() as it is not just rendered (it renders on window.show()).
Second - I can't render FormPanel manually before putting it to Window as it may have layout 'fit' or 'anchor'.

So, I should summize all heights & widths of underlying elements, depending on structure and layouts. For example, if TextField height is 24px, three fields lying one under another gives total height 24*3 = 72. Form.height = Window.height = 72px. And so on. For layouts like 'fit' or 'anchor' I can reserve some space 200px width and something to height.

What do you think this about, is it right method, or it is really mad? :s