Thursday, April 27, 2017

Set InitalMainWindowSize and location of numerous TopComponents

The NetBeans Wiki about DevFaqInitalMainWindowSize already gives an initial hint of how to control the size of your TopComponent at startup.What was missing for me was: How to place 2 (or more) TopComponents (both being of type "editor") next to each other ?

I will show the answer to this in a test  RCP in painful detailed steps to avoid any misunderstandings.

Assume we have a NetBeans Platform application with name PreDefineSize having two modules with names module1 holding the LeftTopComponent and a module2 holding the RightTopComponent.

Performing a Clean and Build and run will give

Assume that we would like the application at startup with both TopComponents next to each other with about 75% to the Left and 25% of the horizontal space to the Right module. I.e. Something like:

How to achieve this ?

1) After you have resized and placed the 2 TopComponents as you want, Click the LEFT module tab (just to make it the last active) and then exit the application.
2) Go to  PreDefineSize/build/testuserdir/config/Windows2Local
3) Copy the WindowManager.wswmgr to the src directory of module1

 4) Go to PreDefineSize/build/testuserdir/config/Windows2Local/Modes
5) Copy the editor.wsmode to the src directory of module1 and rename to editorWsmode.xml
6) Copy the anonymousMode_1.wsmode to the src directory of module1 and rename to editorRightWsmode.xml
7) Go to PreDefineSize/build/testuserdir/config/Windows2Local/Modes/anonymousMode_1
8) Copy the RightTopComponent.wstcref to the src directory of module1

9) Modify the editorRightWsmode.xml file and the value of the "unique" attribute to editorRight

Note :  In line 8 you might see that the "number" attribute is controlling the order.

10) Create the XML layer file in module1 like below

11) From the tree above open the module1- Important Files - XML Layer .... Modes

12) Create a new folder called editorRight

13) Edit the layer.xml in the src directory of module1 file like below

14) Now do a Clean and Build and the application will start with the layout and size you decided in Step 1

Here is the entire test NetBeans project :   PreDefineSize NB Project ZIP

No comments:

Post a Comment