The JSWindow object provides functionality for managing and scripting windows and dialogs in a solution. It supports creating modal and non-modal dialogs, customizing their appearance and behavior, and displaying forms within them. Windows can have properties like opacity, size, location, resizable state, and titles, and they can also maintain their state across sessions using bounds storage. ## Functionality
JSWindow provides constants such as DEFAULT for auto-determined bounds, DIALOG for non-modal windows, and MODAL_DIALOG for modal dialogs. These constants simplify the creation and configuration of different window types.
Properties allow fine control over the window’s characteristics. For example, opacity and transparent control visual appearance, while resizable, undecorated, and storeBounds affect interactivity and persistence. Methods enable developers to show or hide windows, manipulate their size and position dynamically, and manage associated forms.
Windows support advanced features like setting CSS classes for styling, managing design-time properties, and attaching handlers for specific events. These features enhance customization and integration within applications.
Refer to the Creating window documentation for additional details.
// show a dialog that self-determines bounds the first time it it open, then remembers last bounds for future show operationsvar win =application.createWindow("myName",JSWindow.DIALOG);win.setInitialBounds(JSWindow.DEFAULT,JSWindow.DEFAULT,JSWindow.DEFAULT,JSWindow.DEFAULT); // will be shown initially centred and with preferred sizeforms.myForm.show(win);
DIALOG
Window type constant that identifies a non-modal dialog type.
Non-modal dialogs will allow the user to interact with parent windows, but are less independent then windows with WINDOW type.
Dialogs will stay on top of parent windows and are less accessible through the OS window manager. In web-client dialogs will not
open in a separate browser window.
// create a non-modal dialog on top of current active form's window and show a form inside itvar myWindow =application.createWindow("myName",JSWindow.DIALOG);myWindow.show(forms.myForm);
FULL_SCREEN
Value that can be used for bounds in order to specify that a dialog/window should completely fill the screen.
// create and show a window, with specified title, full screenvar win =application.createWindow("windowName",JSWindow.WINDOW);win.setInitialBounds(JSWindow.FULL_SCREEN,JSWindow.FULL_SCREEN,JSWindow.FULL_SCREEN,JSWindow.FULL_SCREEN);win.setTitle("This is a window");controller.show(win);
MODAL_DIALOG
Window type constant that identifies a modal dialog type. Modal dialogs will not allow the user to interact with the parent window(s) until closed.
Dialogs will stay on top of parent windows and are less accessible through the OS window manager. In web-client dialogs will not
open in a separate browser window. NOTE: no code is executed in Smart Client after a modal dialog is shown (the show operation blocks) until this dialog closes.
// create a modal dialog on top of current active form's window and show a form inside itvar myWindow =application.createWindow("myName",JSWindow.MODAL_DIALOG);myWindow.show(forms.myForm);
Properties Detailed
controller
Get the current controller from the window/dialog.
var formName =application.getWindow('test').controller.getName();
opacity
Gets/Sets the opacity property. By default will have value 1 (completely opaque), and can be assigned to values between 0 and 1.
If set then window will also be undecorated. This should be set before the dialog/window is shown, otherwise it has no effect.
var someWindow =application.getWindow("someWindowName");if (someWindow.isVisible() ==false) {controller.show(someWindow);someWindow.resizable =false;}
storeBounds
Tells whether or not the bounds of this window should be stored/persisted (default false).
If true, the window's bounds will be stored when the window is closed. Stored bounds will be used when the window is shown again instead of initialBounds.
For non resizable windows, only location is stored/persisted.
var win1 =application.createWindow("Window 1",JSWindow.WINDOW,null);win1.setInitialBounds(200,200,450,350);win1.title ="Window 1";controller.show(win1);
transparent
Gets/Sets the transparency property.
NOTE: For smart clients, the window must be undecorated or the
servoy.smartclient.allowLAFWindowDecoration property set to true
var someWindow =application.createWindow("someWindowName",JSWindow.WINDOW,null);someWindow.setInitialBounds(200,200,450,350);controller.show(someWindow);var name ="Name: "+someWindow.getName() +"\n"var parent ="Parent: "+ (someWindow.getParent() ==null?"none":someWindow.getParent()) +"\n"var type ="TypeNumber: "+someWindow.getType() +"\n"var height ="Height: "+someWindow.getHeight() +"\n"var width ="Width: "+someWindow.getWidth() +"\n"var undecorated ="Undecorated: "+someWindow.isUndecorated() +"\n"var opacity ="Opacity: "+someWindow.opacity +"\n"var transparent ="Transparent: "+someWindow.transparent +"\n"var locationX ="Location-X-coordinate: "+someWindow.getX() +"\n"var locationY ="Location-Y-coordinate: "+someWindow.getY() +"\n"var info = name + parent + type + height + width + locationX + locationY + undecorated +"\n"var closeMsg ="Press 'Ok' to close this dialog."var infoDialog =plugins.dialogs.showInfoDialog("Window Info", info + closeMsg,"Ok");if (infoDialog =="Ok") someWindow.close()
undecorated
Gets/Sets the undecorated property.
If set then this window will not have any decoration and can't be moved/resized or closed. This should be set before dialog/window is shown, otherwise has no effect.
var someWindow =application.createWindow("someWindowName",JSWindow.WINDOW,null);someWindow.setInitialBounds(200,200,450,350);controller.show(someWindow);var name ="Name: "+someWindow.getName() +"\n"var parent ="Parent: "+ (someWindow.getParent() ==null?"none":someWindow.getParent()) +"\n"var type ="TypeNumber: "+someWindow.getType() +"\n"var height ="Height: "+someWindow.getHeight() +"\n"var width ="Width: "+someWindow.getWidth() +"\n"var undecorated ="Undecorated: "+someWindow.isUndecorated() +"\n"var opacity ="Opacity: "+someWindow.opacity +"\n"var transparent ="Transparent: "+someWindow.transparent +"\n"var locationX ="Location-X-coordinate: "+someWindow.getX() +"\n"var locationY ="Location-Y-coordinate: "+someWindow.getY() +"\n"var info = name + parent + type + height + width + locationX + locationY + undecorated +"\n"var closeMsg ="Press 'Ok' to close this dialog."var infoDialog =plugins.dialogs.showInfoDialog("Window Info", info + closeMsg,"Ok");if (infoDialog =="Ok") someWindow.close()
Methods Detailed
destroy()
Frees the resources allocated by this window. If window is visible, it will close it first by calling hide()
and if that fails because it couldn't be hidden it will return false.
The window will no longer be available with application.getWindow('windowName') and will no longer be usable.
var getWindow =application.getWindow("someWindowName");getWindow.destroy();getWindow =application.getWindow("someWindowName");if (getWindow ==null) {application.output("Window has been destroyed");} else {application.output("Window could not be destroyed");}