Wednesday Jun 19, 2013

Menubars and Toolbars are Optional in the NetBeans Platform

The question of the day comes from Ralf Eichinger, a few days ago in the comments in this blog:

Coming from Java EE and starting to refresh my Swing knowledge, I found your very valuable blog entries. As I am just starting to have a look at the NetBeans Platform, I am confused at seeing the NetBeans menubar and toolbar in all the example applications. This makes me think that all applications implemented with the NetBeans Platform must be heavier than they should be (carrying all the unnecessary menu and toolbar stuff). I (and probably all old school Swing developers) would like to see how easy it is to remove an unneccessary menubar or toolbar. And is the end result (JAR file) smaller when removing these stuff?

And the answer of the day, i.e., in response to the question from Ralf, above, comes from Sean Phillips, who works for NASA on NetBeans Platform applications and will most likely be at JavaOne this year:

What you will find is that the menu and toolbar get populated dynamically by the features you add to your application. It will only be as heavy as you want to make it, though if you want features you have to include the associated support for GUI components. If it is a matter of just not showing these things, you can hide them quite easily. Geertjan has written towards that several times, at https://blogs.oracle.com/geertjan/entry/simplified_usage_of_the_netbeans, for starters.

Great answer, Sean. Indeed, if you don't want a menubar or toolbar in a NetBeans Platform application, simply create a NetBeans module, add a layer file (both of these activities can be done via wizards in NetBeans IDE), and then hide the menubar and toolbar, like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC 
    "-//NetBeans//DTD Filesystem 1.2//EN" 
    "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
    <folder name="Menu_hidden"/>
    <file name="Toolbars_hidden"/>
</filesystem>

Result:


But this will not make a difference in the size of the application. The code for the menubar and toolbar are still in the application, you've simply prevented them from being displayed. As Sean also points out in his response, you can take a different approach—remove the modules you don't need. If you remove the "org.netbeans.core.ui" module (by right-clicking the application, choosing Properties, expanding "platform", and unselected "Core - UI"), you will not have a toolbar anymore, for example. You can even remove all of the UI components from the NetBeans Platform, if that's what you want to do, as explained in this tutorial, which is the very first tutorial in the "NetBeans Platform Fundamentals" section of the NetBeans Platform Learning Trail:

https://platform.netbeans.org/tutorials/nbm-runtime-container.html

Also make sure to read the blog entry that Sean points to, which gives you a complete template for starting your own NetBeans Platform application without menubars and toolbars:

https://blogs.oracle.com/geertjan/entry/simplified_usage_of_the_netbeans

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« June 2013 »
SunMonTueWedThuFriSat
      
29
30
      
Today