How do I adjust the initial size/position of the main window?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

The default initial size of an application based on NetBeans platform is 90% of the whole screen area and the main window is also centered. These defaults can be redefined quite easily:

  • make sure your module has implementation dependency on Core - Windows module, when using NetBeans 6.9 you can use 'weight' attribute instead of implementation dependency.

  • copy file WindowManager.wswmgr from Core - Windows module into the source folder of your own module (you’ll find it in folder core.windows\src\org\netbeans\core\windows\resources\windowmanager)

  • reference the copied file in your module’s XML Layer:

    <folder name="Windows2">
        <file name="WindowManager.wswmgr" url="WindowManager.wswmgr"/>
    </folder>
  • now you can specify either size relative to the size of the whole screen area (the main window will be centered then) which will work on any screen resolution:

    <main-window>
        <joined-properties centered-horizontally="true" centered-vertically="true"
                           relative-width="0.5" relative-height="0.5" />
        <separated-properties centered-horizontally="true" relative-y="0.1"
                           relative-width="0.8" relative-height="0.08" />
    </main-window>

The snippet from windowmanager.wswmgr above makes the default main window size to be half of the whole screen area.

  • or you can specify exact size and location in pixels:

    <main-window>
      <joined-properties x="0" y="0"   width="800"   height="600"
                  relative-x="0.0"   relative-y="0.0"   relative-width="0.0"   relative-height="0.0"   centered-horizontally="false"   centered-vertically="false"
                  maximize-if-width-below="0"   maximize-if-height-below="0"   frame-state="6"/>
     <separated-properties   x="160"   y="116"   width="1280"   height="93"
	   relative-x="0.0"   relative-y="0.0"   relative-width="0.0"   relative-height="0.0"   centered-horizontally="false"   centered-vertically="false"   frame-state="0" />
  </main-window>

The snippet from windowmanager.wswmgr above opens the main window in the upper left corner of the screen and makes its size 800x600 pixels.

  • you can safely ignore separated-properties part, those properties were used for SDI mode which is no longer supported.

  • keep the rest of windowmanager.wswmgr as it was

Note: This way you can also define the default main window state - maximized/minimized/restored, see JavaDoc for possible values.