Today I was working again on the undocked TopComponent that inspired the post Hiding Tabs for Undocked TopComponents, this time adding a custom statusbar to it. And in the process I found a way of adding a banner to a NetBeans Platform application. There might be unexpected side effects with layout, but so far it looks good. 🙂 Here is what my sample application looks like, to explain what I mean by ‘banner’ (the green part in the screenshot).

Sample application with banner

Well, as far as I gather the idea is not brand new. I had a hint from a forum thread that helped to point me in the right direction. Toni mentions there that you can add components outside the control of the window system, but the blog post linked to there no longer exists…

I started by browsing through the GUI elements in debug mode. And I soon found out that by calling

you can find the main panel that contains all the GUI elements. And this panel has a BorderLayout. So lets look at the different parts of the NetBeans IDE as contained in this window to illustrate.

NetBeans IDE showing layout areas

I created a normal JPanel form (I called mine BannerPanel) and added the components that you see on the screenshot to it. Then I created an installer class for the module, and into the restored method I put the following code:

Now you will notice that I am putting the panel into BorderLayout.NORTH, which according to the screenshot earlier is where the toolbar already is. What is in fact in that space is a container panel that keeps the space for the toolbar. So replacing it means that the panel actually starts at the same height as the toolbar. And this means that you need to leave some open space at the top of the panel that you design. See the screenshot below showing my very green form in the GUI designer.

Banner in GUI designer

One last gotcha. You have to specify a height for the form by re-sizing it with the GUI designer. Otherwise the form will end up being small enough to be hidden behind the toolbar.

And remember – this is a way to bypass the NetBeans Platform window system to add components around it. So if things go wrong, you will have to go on a quest to find a Swing guru… 🙂