





















































(For more resources on NetBeans, see here.)
You can get quite far with the standard modes provided by the NetBeans Platform. Still, sometimes you may need to provide a custom mode, to provide a new position for the TopComponents within the application. A custom mode is created declaratively in XML files, rather than programmatically in Java code.
In the following example, you create two new modes that are positioned side by side in the lower part of the application using a specific location relative to each other.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mode PUBLIC
"-//NetBeans//DTD Mode Properties 2.3//EN"
"http://www.netbeans.org/dtds/mode-properties2_3.dtd">
<mode version="2.3">
<name unique="mode1" />
<kind type="view" />
<state type="joined" />
<constraints>
<path orientation="vertical" number="20" weight="0.2"/>
<path orientation="horizontal" number="20" weight="0.5"/>
</constraints>
</mode>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mode PUBLIC
"-//NetBeans//DTD Mode Properties 2.3//EN"
"http://www.netbeans.org/dtds/mode-properties2_3.dtd">
<mode version="2.3">
<name unique="mode2" />
<kind type="view" />
<state type="joined" />
<constraints>
<path orientation="vertical" number="20" weight="0.2"/>
<path orientation="horizontal" number="40" weight="0.5"/>
</constraints>
</mode>
Via the two wsmode files described above, you have defined two custom modes. The first mode has the unique name mode1, with the second named mode2. Both are created for normal TopComponents (view instead of editor) that are integrated into the main window, rather than being undocked by default (joined instead of separated).
The constraints elements in the files are comparable to GridBagLayout, with a relative horizontal and vertical position, as well as a relative horizontal and vertical weight. You place mode1 in position 20/20 with a weighting of 0,5/0,2, while mode2 is placed in position 20/40 with the same weighting.
If all the other defined modes have TopComponents opened within them, the TopComponents in the two new modes should lie side by side, right above the status bar, taking up 20% of the available vertical space, with the horizontal space shared between them.
What should I set the window position to?
In the wizard, in both cases, it does not matter what you set to be the window position, as you are going to change that setting manually afterwards. Let both of them open automatically when the application starts.
<folder name="Windows2">
<folder name="Components">
<file name="BlueTopComponent.settings"
url="BlueTopComponentSettings.xml"/>
<file name="RedTopComponent.settings"
url="RedTopComponentSettings.xml"/>
</folder>
<folder name="Modes">
<file name="mode1.wsmode" url="mode1.wsmode"/>
<file name="mode2.wsmode" url="mode2.wsmode"/>
<folder name="mode1">
<file name="RedTopComponent.wstcref"
url="RedTopComponentWstcref.xml"/>
</folder>
<folder name="mode2">
<file name="BlueTopComponent.wstcref"
url="BlueTopComponentWstcref.xml"/>
</folder>
</folder>
</folder>
In the summary, you defined two new modes in XML files and registered them in the module's layer.xml file. To confirm that the modes work correctly, you use the layer.xml file to register two new TopComponents so that they open by default into the new modes. As a result, you now know how to extend the default layout of a NetBeans Platform application with new modes.