Thursday Jul 31, 2014

Free NetBeans Platform Crash Course

For those who somehow missed seeing this on Facebook, Twitter, LinkedIn, and probably other social media sites... here it is, in very few bits and pieces a basic overview of what the NetBeans Platform entails:

It features Some Guy Who Left (without documenting anything):

And then it shows how to overcome the mess created by that guy.

(That guy looks a tiny bit like JB Brock, except that he's awesome, as proven in this recent interview with him about the recently released "Java EE and HTML5 Enterprise Application Development".)

The whole thing is here:

In other news. I am on vacation until the middle of August and will only sporadically be checking mail, blog comments, Twitter etc.

Wednesday Jul 30, 2014


So you're using MultiViewElements in your NetBeans Platform application. When the user right-clicks one of the tabs they're able to split the editor you've created for them. Here you see the split functionality in the Source tab:

Here you see the split functionality in the Design tab, i.e., in both cases the user right-clicks in the tab and then sees they can split the editor:

However, what if you do NOT want that functionality? In the Branding dialog of the application, look for MultiViewElement.Spliting.Enabled as shown below, then right-click on the word below, choose "Add To Branding" and change the value from 'true' to 'false'.

Then run the application again... and the split functionality is gone in the Source tab:

As well as in the Design tab:

All this and similar branding switches are documented here:

One of the switches in the page above is USE_MNEMONICS, which I discussed here.

Tuesday Jul 29, 2014

Update 5 for "NetBeans Platform for Beginners"

Another monthly update of "NetBeans Platform for Beginners" is available.

Everyone who has already bought the book has received, or will be receiving, an e-mail with instructions on how to get the latest update for free.

All others are warmly invited to join in reading, and commenting on, the (in my humble opinion) best book written about the NetBeans APIs:

To give you a taste of the book, over 50 of its pages are available for free:

Monday Jul 28, 2014

NetBeans API javadoc links to "NetBeans Platform for Beginners"

Jaroslav Tulach has now integrated several references to NetBeans Platform for Beginners into the NetBeans javadoc:

He's also written some very nice things about it here in his API Design blog, a version of which is part of Update 5 of NetBeans Platform for Beginners.

Sunday Jul 27, 2014

Karma: Debugging JavaScript Unit Tests

In NetBeans IDE 8.0, you're able to debug JavaScript unit tests via JS Test Driver. In the upcoming NetBeans IDE 8.0.1, JavaScript unit test debugging has been extended to include Karma, as well.

Right-click an HTML5 project and, when you select Karma in the JavaScript Testing tab, you can enable debugging, as shown below. (The new Karma Istanbul code coverage integration was discussed in this blog yesterday.) 

As you can see below, the drop-down lets you choose on which device you want to debug your unit tests:

Then, on the Karma node of your project, enable debugging and start Karma:

Then you can follow the steps in "Debugging a JS Unit Test with JS Test Driver" in the NetBeans tutorial Debugging and Testing JavaScript in an HTML5 Application, with the result shown below, click to enlarge the image.

Saturday Jul 26, 2014

Karma Istanbul Code Coverage in NetBeans IDE

Nice job—all your tests are passing. However, it's pretty useful to at least know the percentage of code that's under test. No one's saying that all your code should be under test, just that it's hard to argue against being able to be aware that your 100% test pass rate applies to 20% of your code.

In the JavaScript world, a popular solution in this area is Karma Coverage, which is based on Istanbul, and for which the upcoming NetBeans IDE 8.0.1 has handy integration:

Look at the above screenshot—with one glance you can see the statement in my code that has not been tested.

To get to the above screenshot, I read this article and then checked out this code on GitHub, and then simply opened it in NetBeans IDE, and clicked the menu items that you see above that appear magically on the project when opened into NetBeans IDE, while this is also handy.

Here's the test spec for the above JavaScript file, notice that one test method is commented out. If it were not commented out, the above code coverage would pass 100%.

describe("sqrt", function() {

//  it("should compute the square root of 4 as 2", function() {
//    expect(My.sqrt(4)).toEqual(2);
//  });

  it("should throw an exception if given a negative number", function() {
    expect(function(){ My.sqrt(-1); }).toThrow(new Error("sqrt can't work on negative number"));


For a fullblown NetBeans IDE tutorial on debugging and testing HTML5/JavaScript applications, see this document, though note that it doesn't include code coverage yet, since that's not in the current release of NetBeans IDE:

Friday Jul 25, 2014

Grunting in NetBeans IDE

Grunt tasks are to JavaScript what Ant targets and Maven goals are to Java.

You can "grunt" on the command line, but also directly in NetBeans IDE.

Here I'd like to take a look at where the feature set in NetBeans IDE is going with Grunt.

Let's say we've got hold of the AngularJS Seed template. Doing this is simple in NetBeans IDE via the New HTML5 Project wizard, which gives you an option to let NetBeans IDE download the AngularJS Seed template as the basis of the new application.

Once you have your application, hop over to the New File dialog and create your Grunt file:

Next, here's a handy Grunt definition that creates three tasks, for copying to a 'build' directory, for cleaning that directory, and for combining the two tasks, thanks to this article:

module.exports = function (grunt) {
        pkg: grunt.file.readJSON('package.json'),
        'Compiles all the assets and copies the files to the build directory.',
       [ 'clean', 'copy' ]

Copy the above into your Grunt file. The above means that in the 'package.json' file that is already part of the AngularJS Seed template, you need to add two new dependencies, shown in bold below:

"devDependencies": {
"karma": "~0.10",
"protractor": "~0.20.1",
"http-server": "^0.6.1",
"bower": "^1.3.1",
"shelljs": "^0.2.6",
"karma-junit-reporter": "^0.2.2",


Then right-click on the project and choose "Npm install", which is new in the upcoming NetBeans IDE 8.0.1, though the development builds are already available:

Then, also new in NetBeans IDE 8.0.1, right-click on the project and notice that you have access to the tasks via the new "Grunt Tasks" menu item:

Also, again new in NetBeans IDE 8.0.1, you can map your Grunt tasks to project commands:

Now, when you right-click your project and choose "Build", "Clean", and "Clean and Build", you automatically delegate the handling of the action to the underlying Grunt task.

The icing on the cake is that the project commands "Build", "Clean", and "Clean and Build" can be mapped to keyboard shortcuts. For example, map "Build" to a keyboard shortcut and then, when it is pressed, the related Grunt task of the currently active project will be invoked.

Grunt could almost not be integrated more snugly into NetBeans IDE. Maybe an enhancement could be to provide some predefined templates as examples of what can be done with Grunt, to really get you up and running quickly.

Related reading:

Thursday Jul 24, 2014

Bower and Node.js in NetBeans IDE

With more and more HTML5/JavaScript/CSS3 frameworks using packaging solutions provided by Bower and Node.js, it can become a bit tricky for you to set up projects... hard to see the forest for the trees sometimes with so many different solutions striving valiantly to help you but tripping each other up in the process. Despite their innovations, it also becomes slightly cumbersome to share projects with team members because each of them need to run Bower and/or Node.js on the command line, before beginning with their programming tasks. Finally, it becomes difficult for NetBeans IDE to bundle HTML5 sample projects efficiently, as described in my earlier blog entry AngularJS Seed, Bower, and NetBeans IDE 8.

However, in the upcoming NetBeans IDE 8.0.1 release, there's a very elegant mechanism that helps bridge the flexibility offered to frameworks by Bower and Node.js with the assumptions one has when getting started with predefined project structures and when working with shared projects.

Let's go through the process, using a daily development build of the pure HTML5/PHP distribution of NetBeans IDE. First, create a new HTML5 application:

Give it a name and location:

Choose the Angular Seed Template:

The above means that a connection is made to the on-line repository where the HTML5 Angular Seed template is found. The team responsible for that template can change it anytime they like, which is exactly what they're doing now and then, by changing the structure of the seed template as well as the libraries it depends on.

On completing the wizard, notice (for the first time in NetBeans IDE 8.0.1) the error badge in the project icon and the project name is in red:

That tells you that some of the dependencies declared by Bower or Node.js or both have not been satisfied.

Right-click and notice 'Npm install' and 'Bower install' can be called directly from here, as well as 'Resolve Project Problems':

When you select that menu item, NetBeans IDE tells you 'hey, there's a bunch of stuff missing, based on analysis of the Bower and Node.js definitions in your project':

When you click "Resolve" above, all the stuff that needs to be added to the project is automatically added, below a very small segment of all the stuff that happens in the background for you is shown:

Now that's pretty cool. Whenever you open any HTML project into NetBeans IDE, i.e., straight via a template like the above, or by opening a project with existing sources on disk, NetBeans IDE will tell you whether Bower or Node.js should be run, and it will then run it for you, and thereby resolve project dependency problems for you... so that you can begin coding really quickly without having to worry about all these messy set up details. 

Also, this makes sharing projects between team members nice and easy. Define your dependencies via Bower or Node.js, pass the project to your team members however you like, and then let NetBeans IDE access the dependencies and add them to the project for you. 

In short, this really feeds in very well to the concept of "Integrated AngularJS Development".

Wednesday Jul 23, 2014

Distinct Icons per Java Type in NetBeans IDE

Especially useful in the editor tabs, where you could have multiple documents open at the same time, often not with names that reveal the type, and now you can quickly ascertain the type via each tab, i.e., here you can immediately see which one is the interface:

For details:

Many thanks Hermien Pellissier from South Africa for raising this issue! It will be available from NetBeans IDE 8.0.1 onwards.

Tuesday Jul 22, 2014

World's Simplest NetBeans Node/TopComponent Implementation

In 2008, here, I documented the world's simplest NetBeans Node implementation. Here's the updated implementation, using ChildFactory, together with the code needed for connecting it into a TopComponent:

public final class ViewerTopComponent extends TopComponent implements ExplorerManager.Provider {
    private ExplorerManager em = new ExplorerManager();
    public ViewerTopComponent() {
        setLayout(new BorderLayout());
        add(new BeanTreeView(), BorderLayout.CENTER);
        Children kids = Children.create(new SystemPropertyChildFactory(), true);
        AbstractNode rootNode = new AbstractNode(kids);
        associateLookup(ExplorerUtils.createLookup(em, getActionMap()));
    public ExplorerManager getExplorerManager() {
        return em;
    class SystemPropertyChildFactory extends ChildFactory<Object> {
        protected boolean createKeys(List<Object> list) {
            return true;
        protected Node createNodeForKey(Object key) {
            BeanNode node = null;
            try {
                node = new BeanNode(key);
            } catch (IntrospectionException ex) {
            return node;

Here are the class annotations for registering the above in the Window System:

        preferredID = "ViewerTopComponent",
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
        mode = "explorer",
        openAtStartup = true)
        category = "Window",
        id = "org.demo.viewer.ViewerTopComponent")
        path = "Menu/Window" /*, position = 333 */)
        displayName = "#CTL_ViewerAction",
        preferredID = "ViewerTopComponent"
    "CTL_ViewerTopComponent=Viewer Window"

And here are the import statements:

import java.awt.BorderLayout;
import java.beans.IntrospectionException;
import java.util.List;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.explorer.view.BeanTreeView;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.BeanNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;

Monday Jul 21, 2014


The recently held NetBeans Platform course in Leipzig has resulted in a very nice enhancement for the NetBeans Platform community. It can be read about here, by its author Daniel Koll, from Aachen:

TopComponentGroup mit Annotation

No worries if you don't understand German. All you need to understand is Java! 

To get started with this enhancement, do a checkout:

svn checkout svn:// topcomponentgroupregistration-code

You'll end up with a NetBeans module that defines a @TopComponentGroupRegistration, as follows.

public @interface TopComponentGroupRegistration
   * The module where the {@link TopComponent} is placed in, and where the Group will 
   * be placed in if it doesn't exist.
   * @return 
  public String module();
   * The specification Version of the {@link #module()}.
   * @return 
  public String specVersion() default "1.0";
   * The name of the Group, where this {@link TopComponent} will be placed.
   * @return 
  public String group();
   * Value of the open Flag, in the Group Configuration.
   * @return 
  public boolean open() default true;
   * Value of the close Flag, in the Group Configuration.
   * @return 
  public boolean close() default true;
   * Flag, if the Group should be opened at startup.
   * The real state of the group is calculated via an or to all 
   * of these Items.
   * @return 
  public boolean groupOpenState() default false;

There's also a LayerGeneratingProcessor included in the NetBeans module, to process the above. 

Copy both into a core module in your NetBeans Platform application, set the required dependencies (just copy them from the project.xml in the module) and then annotate your TopComponents as needed, as described by Daniel Koll.

Many thanks, this is very useful, and has qualified Daniel Koll as a NetBeans Platform Certified Engineer. This is a certification that is part of the NetBeans Platform Certified Training Course. Not only that, but Daniel has created another new feature, available as a plugin, ImportantFiles 4 JavaSE. Congratulations Daniel, looking forward to many more enhancements to NetBeans IDE!

Friday Jul 18, 2014

French, Polish, Dutch Updated Translations of NetBeans Platform

Mixing existing translations from the community translation project with new supplemental translations, as described here, we now have NetBeans Platform translations updated to Polish, French, and Dutch during the last few days:

French, by Constantin Drabo:

Polish by Sławek Mikuła:

Dutch by me:

If you want these translations as the basis of your own work, let me know in the comments to this blog entry. We're collecting the translations at, which is currently only accessible if you're a member of the project. We'll open the site soon so anyone can access it.

Even the above are not complete translations yet, we're just focusing on the visible texts that we see as we look through the menus, dialogs, etc, of the NetBeans Platform. It's a slightly haphazard process but better than nothing. Translators who complete the 'platform' translation, then start working on the 'ide' translation, which is a separate application on top of 'platform', followed by 'javase', etc, etc, one step at a time, until all of the IDE is translated.

Wednesday Jul 16, 2014

NetBeans Translation Tip #1: Page Setup Dialog

No matter what you do, you're unable to translate the "Page Setup" dialog, which is accessed from "File | Page Setup..." in the main menu of the NetBeans Platform. 

The reason for the problem is that the strings that you see above do not come from the NetBeans Platform. Instead, they come from the JDK, specifically, from rt.jar, where you'll find the following:

The above screenshot shows which languages are supported for the Page Setup dialog. Therefore, if you switch locale to "pl" for Polish or "nl" for Dutch or some other language not listed above... the English texts will be shown and nothing you do with properties files in the 'branding' folder in your NetBeans Platform application is going to change that.

But there is a solution.

  1. Get the source. Go here, i.e., the source of sun.print.resources.serviceui, and copy that source file into the NetBeans module for your language. Change the name of the class to include your locale, e.g., "" and, to help yourself later to understand why it's there, put it into the same package structure as the other files in rt.jar.

  2. Translate the texts. Then translate all those texts, e.g., the key "radiobutton.portrait" currently has the value "Portrait". Translate that word "Portrait" and replace the value with your translated word. Do the same for all the values in the file, of which there are about 150, I guess.

  3. Install the translation. Then create this class in your language module:
    import java.lang.reflect.Field;
    import java.util.Locale;
    import java.util.ResourceBundle;
    public class PageSetupTranslator implements Runnable {
        public void run() {
            ResourceBundle bundle = 
                            new Locale("nl", "NL"));
            try {
                Class cl = Class.forName("sun.print.ServiceDialog");
                if (cl != null) {
                    Field fld = cl.getDeclaredField("messageRB");
                    if (fld != null) {
                        fld.set(cl, bundle);
            } catch (ClassNotFoundException ex11) {
            } catch (NoSuchFieldException ex11) {
            } catch (SecurityException ex11) {
            } catch (IllegalArgumentException ex11) {
            } catch (IllegalAccessException ex11) {

  4. Check the module structure. You should now see the following structure in your language module:

Now, when you start the application, your "serviceui" class will be picked up and applied to the Page Setup dialog. Of course, when there are multiple such classes, as will be the case in the "LocalizeNetBeans" project, there'll be a problem because multiple of these files will be applied to the Page Setup dialog. Just disable all of them by commenting the @OnShowing annotation for all of them except your own during development and in production the user will only be using one language anyway and, if they need more, they'll switch to a different locale, restart their application, and then the class applicable to the locale will be applied to the Page Setup dialog.

Tuesday Jul 15, 2014

Lightweight Process for Translating NetBeans IDE

To me, the problem with translating NetBeans IDE over the years has been that the process has always been very complicated with all kinds of tools that need to be set up.

Wouldn't it be cool if there was a simple, lightweight process. One that anyone can follow, in between doing other work, i.e., quickly dedicate half an hour every day to translating NetBeans IDE, whilst doing other work? No new tools to set up, no new and complex processes to learn? Everything done from within NetBeans IDE itself?

Here's how that can be achieved. Some steps have small YouTube clips to illustrate points made. These YouTube clips are silent, the idea is to watch and learn from the process.

  1. Get Set Up. Download and unzip the last community translation distribution, i.e., the one that contains more than the official translations, e.g., Russian, but the community translations, e.g., German and French. They're found here and I started with the

    Then get hold of the "Localized NetBeans" project. This is a project I have created on and isn't public yet. That will happen soon. If you want to participate, let me know (leave a comment at the end of this blog entry with your username included), I will add you as a member to the project, which will give you access to the project sources. The location is though, again, without being a member you will not be able to get to the project site.

  2. Set Up the Translation Module. As described in a recent blog entry, here, a NetBeans Platform application can provide modules with translated texts for UI elements in the application, which can be enabled via the --locale switch. Therefore, if it doesn't already exist, create a new module for your language in the "LocalizedNetBeans" project and move the JARs from step 1 that already provide translations into the module.

    Small overview for adding Korean:

    If you're doing a language for which no JARs already exist, just skip this step and go straight to the next one, i.e., for Serbian you'll start by writing down some texts that you want to translate, then look for them in the Branding dialog after selecting the Serbian locale, and have NetBeans IDE create properties files automatically for you. See the next step for the details.

  3. Start Translating. Any missing translations? Look around, identify what's missing, look for the texts in the Branding tool in NetBeans IDE, and add them.

    Small overview for translating to Korean:

    Remember, when searching for texts in the Branding tool, that if a text has an underline, e.g., "Options" with the "O" underlined (to create an accelerator key), you need to look for "&Options".

  4. Move to the Next Level. Once the "LocalizedNetBeans" has been translated, i.e., the lowest level of NetBeans IDE, which is the NetBeans Platform, move to the next level, which is already available, i.e., "LocalizedIDE". The focus here is on the "ide" cluster, e.g., the project system, and other tools that related to an IDE created on top of the NetBeans Platform.

    Small overview for moving from "platform" to "ide":

    "LocalizedIDE" depends on the cluster of "LocalizedNetBeans", so that those translations are automatically included.

    After the above is done, the next level would be "LocalizedJavaSENetBeans", where the focus is to provide the missing translations for your language in the community distribution for the Java SE distribution of NetBeans IDE, i.e., the Java Editor and related tools. "LocalizedJavaSENetBeans" will depend on the cluster of "LocalizedIDE".

  5. Check In. At the end of the previous steps, you'll possibly have one or more new modules, if your language wasn't supported yet, and you'll definitely at least have new properties files in the 'branding' folder of "LocalizedNetBeans", "LocalizedIDE", etc. Check those in. When there are enough of them, or when you say you're done, or at some stage when at least all the visible texts have been translated, I will put those properties files together into one or more new NetBeans modules. There'd be one module for the 'platform' translation of Korean, one for the 'ide' translation, etc, because not everyone will want all the translations, e.g., if you're creating an application on the NetBeans Platform, you don't want the Java Editor translations, so best to keep them separated per 'level'. Those various modules will be uploaded together to the NetBeans Plugin Portal. Anyone can download and install them and use the --locale switch to activate them. So we'll end up with language packs for each language, available on the Plugin Portal.

On the 'platform' level, i.e., the level of "LocalizedNetBeans", most things are already translated for most supported community languages. I.e., if you're using the NetBeans Platform, German and French and Spanish and Italian translations are mostly complete already, a few gaps here and there which won't take much work to add by a native speaker. And the above approach can also be used to add new modules, for Serbian, for example.

The process is simple and completely integrated into NetBeans IDE so that anyone can, in between programming, do a little bit of translation work.

Want to participate? Leave a comment that includes your username so that you can be added to the project and so that you can start following the steps described above.

Monday Jul 14, 2014

Monet: Tight JavaFX Scene Builder Integration in NetBeans IDE

With an appropriate sense of flair, Sven Reimers has published his JavaFX Scene Builder/NetBeans integration module under the name "Monet", i.e., in the same series of project names as "Matisse", the NetBeans Swing GUI Builder.

Get it here:

Small silent movie by me highlighting a subset of its features:

Be aware that I am using BizLaf, hence my IDE looks pretty different to the standard NetBeans IDE.

And note that Monet is far from done:

Saturday Jul 12, 2014

How to Bundle Localized NetBeans Modules with Ant Based NetBeans Platform Applications (Part 2)

After learning the basics of bundling localized JARs in Ant based NetBeans Platform applications, yesterday, let's now provide support for a language that is not officially supported by NetBeans IDE, i.e., a language other than English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese. Timon Veenstra's team working on the AgroSense project have done us all a big service by creating the NetBeans Maven Libraries project on (How to integrate that into a Maven NetBeans Platform application is described here.)

We're going to go there and get the localized JARs we need. They're from NetBeans Platform 7.2, which isn't actually much of a problem because on the level of the NetBeans Platform, which is what most NetBeans Platform developers use (i.e., most developers build on the NetBeans Platform and not on the NetBeans IDE on top of it) not much has changed in terms of UI and strings in general, since most changes over the past few releases have been focused on the level of new and enhanced APIs, not new and enhanced GUI components and other string-bearing-stuff. We'll download the ones we want and put them into the same structure as in yesterday's blog entry.

The requirement we imagine we have is that we want to provide a Spanish translation of our NetBeans Platform application. In the first stage, we're going to get the Spanish JARs we need from Timon Veenstra's project and, after that, for any missing translations, you're going to learn how to supplement the project with your additional localizations.

  1. Go to

  2. For the language of your choice, download the JARs you need. I.e., go to 'core', 'lib' and 'modules', find all 'es' JARs, download them (by right-clicking on the JAR and saving it or by checking out the entire project). As described yesterday, create a new module for each language you want to support, switch to the Files window, and create a 'release' folder, on the same level as 'nbproject' and 'src' and then populate that folder with the relevant JARs that you downloaded.

    Brief description of the strings found in each of the above JARs:

    JAR Description
    core_es.jar Strings such as error messages and module loading/installation messages, e.g., MSG_load_layers=Cargando servicios de módulo...
    boot_es.jar Strings such as the question to show the user to find out whether to start a second instance of the application or not.
    org-netbeans-api-search_es.jar Strings for Search Results window, e.g., title of Output tab, as well as "Find in Projects", "Replace in Projects", etc.
    org-netbeans-core-execution_es.jar String for processes, such as external processes, e.g., CTL_PendingExternalProcess2=Proceso: {0}.
    org-netbeans-core-io-ui_es.jar Strings for Output window, e.g., Menu/Window/Output=&Salida.
    org-netbeans-core-multiview_es.jar Strings for working with multiview components, e.g., CTL_Save=Guardar.
    org-netbeans-core-output2_es.jar Strings for windows related to Output window, e.g., LBL_Find_Title=Buscar and Output window tab, e.g., LBL_Close=Cerrar Separador.
    org-netbeans-core-ui_es.jar Strings for the menubar, e.g., Menu/Edit=&Editar and many actions, e.g., como...
    org-netbeans-core-windows_es.jar Strings for the window system, e.g., CTL_CloneDocumentAction=C&lonar Documento and Actions/Window=Ventana.
    org-netbeans-core_es.jar Strings related to the About Box, e.g., About=&Acerca de and Exit, e.g., Exit=&Salir.


    Strings related to the Plugin Manager and the update mechanism, such as install=Instalar de todos modos and InstallUnitWizard_Title=Installer de Plugins.
    org-netbeans-modules-favorites_es.jar Strings for the Favorites window, such as Favorites=Favoritos and ACT_Add=&Agregar a Favoritos.


    Strings related to the Options window, such as CTL_Options_Dialog_Title=Opciones and CTL_Export=Expor&tar and CTL_Keymap_Options=Asi&gnación de Teclas.
    org-netbeans-modules-print_es.jar Strings for the Print and Page Setup features, such as MNU_Print_Action=Im&primir...
    org-netbeans-modules-progress-ui_es.jar Strings for the progress bar, such as Cancel_Question_Title=Cancelar Tarea en Ejecución.
    org-openide-actions_es.jar Strings for many generic actions, such as cut, copy, paste, and delete.
    org-openide-loaders_es.jar Strings relating to files, such as SaveAsTemplate=Guardar como Plantilla...

    As far as I am (currently) aware, the above are the only JARs you need to think about including (if you are creating a generic NetBeans Platform application, as opposed to one that is based on NetBeans IDE and/or uses various kinds of editors, e.g., the NetBeans XML Editor), there are several other JARs in the 'platform' folder, but these don't have strings in them. (One other one to remember is modules/ext/locale/updater.jar.) Also remember that in each case, the above are JARs that contain nothing more than a few properties files, i.e., they're tiny JARS with almost no content at all, aside from the properties files with the translated strings in them.

    Of course, all the other languages are the same as the above, to the extent that they have been translated. I.e., the keys are the same for all languages, but the values are different, obviously since they're all different languages, and the extent to which they have been translated is also different.

  3. Run the application with --locale es or -J-Duser.language=es. Lots of Spanish texts everywhere now, as you can see in the screenshot below. However, not everything has been translated, for various reasons, e.g., the "Show Only Editor" menu item is new in NetBeans IDE 7.4, and hence didn't exist when the 7.2 localization JARs were created:

  4. Right-click the application and choose Branding. Go to the "Internationalization Resource Bundles" tab. Then choose the locale you're interested in, which in this case, since we're working on Spanish, is "es". After that use the search field to look for your string.

    Be very careful if the string, as in the case of "Show Only Editor" has an underline in it, as in this particular case under the "O", which is caused by an ampersand prior to that letter, resulting in the NetBeans Platform creating an accelerator so that the user can use the keyboard to get to that menu item. Therefore, when you do your search for a string that includes an underline, replace the underline with an ampersand prior to the underlined letter, as shown below:

    Once you've found your string, right-click on it in the dialog above, choose "Add to Branding", and then type the, in this case, Spanish translation of the string.

    What's also really cool about the above dialog is that, as you can see above, you now have a pretty good idea in which module the string is found, i.e., which JAR is going to be overridden: 'org-netbeans-core-windows' in this case, with the 'actions' being a package in that JAR.

  5. Now switch to the Files window. Expand the 'branding' folder in the application. You'll notice that, after doing the previous step, NetBeans IDE has automatically created a folder for you named 'org-netbeans-core-windows.jar'. That's a folder. Continue expanding it and in the 'actions' folder you'll find your translated string.

  6. Run the application again and you'll see your translated texts automatically merged with the localization JARs that you downloaded from Timon Veenstra's project.

It would be pretty cool if anyone who supplements the localization JARs with their own translations for any language would let the NetBeans team know, e.g., at the end of this blog entry, or at netbeans dot webmaster at gmail dot com, that you've done a translation and then those translations can be added together and published as a whole for everyone to benefit from.

Friday Jul 11, 2014

How to Bundle Localized NetBeans Modules with Ant Based NetBeans Platform Applications (Part 1)

Let's figure out a solid approach to including localization bundles in our Ant-based NetBeans Platform application. (For Maven, go here.)

  1. Go to Find the drop-down "IDE Language" at the top right of the page. Choose your language. Click Download under the Download Bundle you need, which is most likely to be "Java SE".

  2. Install the download bundle. If you already have NetBeans IDE 8.0 installed, you'll need to first uninstall it because the download bundle will discover, right at the start of the installation procedure, that NetBeans IDE 8.0 is already installed. So uninstall your NetBeans IDE and then reinstall using the new download bundle.

  3. Start up NetBeans IDE. Open your NetBeans Platform project into it.

  4. For each language for which you want to provide support, create a new module. That's a modular solution, each language in its own module. Switch to the Files window and there, at the same level as 'nbproject' and 'src', create a folder 'release/core/locale' and a folder 'release/modules/locale', containing all the JARs from the download bundle that you'd like to include in the module:

    The above entails that you need to look in your NetBeans IDE installation folder, in the 'locale' folder of the 'platform' folder for the JARs applicable to your language that are relevant to your application. Note that 'core' and 'modules' above match the 'core' and 'modules' subfolder of 'platform' where the JARs above are found:

  5. Continue doing the above until you have all the JARs that you need. Make as many modules as there are languages that you'd like to support for which translated JARs exist.

  6. Bear in mind that if you have a locale like "pt_BR", then this is the way you specify the second part, in the 'run.args.extra' line and/or in the default_options line in the .conf file of the application.
    run.args.extra=--laf Nimbus -J-Duser.language=pt -J-Duser.region=BR 
  7. Run the application and see, for example, the following, i.e., below the fact that org-netbeans-core-ui_pt_BR.jar is included means that the menubar, among other UI pieces, is now in Portuguese (Brazil):

That's it. Interested to know what NetBeans Platform developers out there think of this. It's all pretty nice except for the fact that you need to figure out in which JAR the texts are found that are of interest to your application. In another blog entry I'll suggest some approaches for that, though the simplest approach is to simply include all the localized JARs for your language from the 'platform' folder. They don't contain anything other than properties files, i.e., they're really small.

Thursday Jul 10, 2014


In many scenarios with the NetBeans Platform, such as the NetBeans Platform CRUD Tutorial, you have two windows that need to interact with each other whilst being in two different modules.

The standard advice in this above scenario is to publish an object, e.g., Customer, into the Lookup, via one TopComponent (typically a viewer window), while the other TopComponent (typically an editor window) subscribes to that object. But to which Lookup should the second TopComponent subscribe? The global Lookup? In that case, when any TopComponent is selected that does not have the Customer in its Lookup, the global Lookup will not have the Customer available either. Normally, if this is a problem, you subscribe to the Lookup of the first TopComponent, which means your TopComponents are now tightly coupled to each other.

Tim Boudreau's blog, here, summarizes how you can replace the global Lookup with your own ContextGlobalProvider, while Bruce Schubert, here on NetBeans Zone and here on the NetBeans Wiki, goes into a lot more detail. Read the related javadoc, too.

Below, I've tried to simplify Bruce's code significantly, specifically for the Customer object in the NetBeans Platform CRUD Tutorial. Copy the code below, paste it into any module in your application, make sure to set an implementation dependency in that module on the Window System API, since an internal class is referenced. Then, whenever the context switches, e.g., a different TopComponent is selected, one that does not provide a Customer object in its Lookup, the last published Customer object is made available. And you can continue using Utilities.actionsGlobalContext().lookupResult(Customer.class) without a problem, i.e., your TopComponents will remain disconnected from each other.

More comments and explanations below, by Bruce, tweaked slightly here and there by me, all errors and mistakes my own responsibility.


import demo.Customer;
import java.util.Collection;
import org.openide.util.ContextGlobalProvider;
import org.openide.util.Lookup;
import org.openide.util.Lookup.Result;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.util.lookup.ProxyLookup;
import org.openide.util.lookup.ServiceProvider;

 * This class proxies the original ContextGlobalProvider and ensures the current
 * customer remains in the GlobalContext regardless of the TopComponent
 * selection.
 * To use this class you must edit the Windows System API module dependency:
 * change the dependency to an implementation version so that the
 * package is on the classpath.
 * @see ContextGlobalProvider
 * @see GlobalActionContextImpl
 * @author Bruce Schubert & Geertjan Wielenga
        service = ContextGlobalProvider.class,
        supersedes = "")
public class GlobalActionContextProxy implements ContextGlobalProvider {

     * The proxy lookup returned by this class:
    private Lookup proxyLookup;
     * The native NetBeans global context lookup provider and
     * the official global lookup managed by the NetBeans Platform:
    private final GlobalActionContextImpl globalContextProvider;
    private final Lookup globalContextLookup;
    private final LookupListener globalLookupListener;
     * Additional customer content for our custom global lookup:
    private Lookup customerLookup;
    private final InstanceContent customerInstanceContent;
    private final Result<Customer> resultCustomers;
     * The last customer selected:
    private Customer lastCustomer;
     * Critical section lock:
    private final Object lock = new Object();

    public GlobalActionContextProxy() {
        this.customerInstanceContent = new InstanceContent();
        // The default GlobalContextProvider:
        this.globalContextProvider = new GlobalActionContextImpl();
        this.globalContextLookup = this.globalContextProvider.createGlobalContext();
        // Monitor the existance of a Customer in the official global lookup:
        this.resultCustomers = globalContextLookup.lookupResult(Customer.class);
        this.globalLookupListener = new LookupListenerImpl();

     * Returns a ProxyLookup that adds the current Customer instance to the
     * global selection returned by Utilities.actionsGlobalContext().
     * @return a ProxyLookup that includes the original global context lookup.
    public Lookup createGlobalContext() {
        if (proxyLookup == null) {
            // Create the two lookups that will make up the proxy:
            customerLookup = new AbstractLookup(customerInstanceContent);
            proxyLookup = new ProxyLookup(globalContextLookup, customerLookup);
        return proxyLookup;

     * This class listens for changes in the Customer results, and ensures a
     * Customer remains in the Utilities.actionsGlobalContext() if a customer is
     * open.
    private class LookupListenerImpl implements LookupListener {
        public void resultChanged(LookupEvent event) {
            System.out.println("resultChanged: Entered...");
            synchronized (lock) {
                // First, handle customers in the principle lookup
                if (resultCustomers.allInstances().size() > 0) {
                    // Clear the proxy, and remember this customer. 
                    // Note: not handling multiple selection of customers.
                    lastCustomer = resultCustomers.allInstances().iterator().next();
                    System.out.println("resultChanged: Found customer ["
                            + lastCustomer.getName()
                            + "] in the normal lookup.");
                } else {
                    // Add the last used customer to our internal lookup
                    if (lastCustomer != null) {

     * Unconditionally clears the customer lookup.
    private void clearCustomerLookup() {
        Collection<? extends Customer> customers = customerLookup.lookupAll(Customer.class);
        for (Customer customer : customers) {

     * Replaces the customer lookup content.
     * @param customer to place in the customer lookup.
    private void updateCustomerLookup(Customer customer) {
        if (customer == null) {
            throw new IllegalArgumentException("customer cannot be null.");
        // Add the customer if an instance of it is not already in the lookup
        if (customerLookup.lookup(Customer.class) == null) {
            System.out.println("updateCustomerLookup: added ["
                    + lastCustomer.getName()
                    + "] to the proxy lookup.");


Wednesday Jul 09, 2014

Book Review: JavaFX 8 -- Introduction by Example

JavaFX 8: Introduction by Example is the book that you absolutely must get hold of if you're interested in JavaFX in any way at all. The authors (Carl Dea, Mark Heckler, Gerrit Grunwald, José Pereda, and Sean Phillips) are all awesome and famous in the JavaFX community and the chapters are purely practical and useful, and well written, and even humorous at times. You couldn't ask for a better combination of people and topics in a book dedicated to JavaFX.

The chapters are as follows:

  1. Getting Started
  2. JavaFX Fundamentals
  3. Lambdas and Properties
  4. Layouts and UI Controls
  5. Graphics with JavaFX
  6. Custom UIs
  7. Media with JavaFX
  8. JavaFX on the Web
  9. JavaFX 3D
  10. JavaFX and Arduino
  11. JavaFX on the Raspberry Pi
  12. JavaFX and Gestures

My current interest lies in the Raspberry Pi and so I was very pleased to find the JavaFX and Raspberry Pi chapter by Mark Heckler and José Pereda and dove in immediately:

It's kind of geek humor, but I found it quite funny to read the EPUB version of the book, i.e., a book all about JavaFX, in an EPUB Reader that I've made... in JavaFX! Maybe I'll get to deploy it to the Raspberry Pi soon (once I figure out how to connect my LCD display to the Raspberry Pi):

The entire book can be seen as a NetBeans IDE tutorial, since NetBeans IDE is used from beginning to end, which is awesome. Aside from that, everything is useful and practical and, as I said above, you should buy it immediately. As in, right now, this minute:

Tuesday Jul 08, 2014

Book Review: Murach's Java Servlets and JSPs (3rd Edition)

Two of the most popular IDEs for developing Java web applications are NetBeans and Eclipse. Both are open-source, and both are available for free. Of the two, we think that NetBeans is easier to use, especially when you're getting started with programming. That's why we recommend that you use NetBeans with this book.

The above, on page 20 of the brand new still slightly sizzling hot off the presses "Murach's Java Servlets and JSPs (3rd Edition)" (June 2014), by Joel Murach and Michael Urban, is a promising signal to all NetBeans fans everywhere. Indeed, chapter 3 starts with about 10 pages of introductory texts, with screenshots, focused on NetBeans IDE 8. The remainder of the book uses NetBeans IDE throughout, in the instructions and getting started sections, as well.

Beyond its clear position on NetBeans IDE, the book consists of 744 pages, making for a very nice doorstop should you manage to read right through it all and remember for all time every single word therein.

Section 1 focuses on "getting started right", via beginner texts relating to JSPs, servlets, MVC, NetBeans, Tomcat, and MySQL. Section 2 guides you through all the key topics relating to JSPs and servlets, including HTML5 and CSS3, sessions and cookies, expression language and JSTL. Section 3 takes you on a tour of "essential database skills", from MySQL to JDBC to JPA. Then follows section 4, on advanced topics, which turn out to be JavaMail, SSL, security/authentication, listeners, and JSF. Very nice to see JSF addressed in this way, i.e., after learning everything else, you then learn about JSF (from page 614). The chapters end with sections offering perspectives, summaries, and exercises, to really drive the key points home.

Section 5, spanning about 50 pages, shows you step by step how to apply the previous sections of the book in the creation of a music store website. You start with the user interface, then the business layer, then the controller layer, the structure, the database, the data layer, and different user interfaces for different kinds of users, i.e., administrators vs. standard users.

A wonderful book. Ideal for self learners, i.e., set aside a few hours each week, for several months, and by the end you'll have learned a lot of good stuff.


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.


« July 2014 »