Monday Feb 10, 2014

Centralized Search Action

Here's how to show the Quick Search textfield in a dialog by clicking a menu item.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JPanel;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.awt.Actions;
import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.Presenter;

        category = "Edit",
        id = "org.bla.SearchAction"
        displayName = "#CTL_SearchAction"
@ActionReference(path = "Menu/File", position = 1300)
public final class SearchAction implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        JPanel panel = new JPanel(new BorderLayout());
        Action qs = Actions.forID("Edit", "org.netbeans.modules.quicksearch.QuickSearchAction");
        Component quickSearchToolbarItem = ((Presenter.Toolbar) qs).getToolbarPresenter();
        panel.add(quickSearchToolbarItem, BorderLayout.CENTER);
        DialogDescriptor dd = new DialogDescriptor(panel, "Search");

Thursday Feb 06, 2014

Functional Interfaces in the NetBeans Platform

SaveCookie, and the other loosely coupled capabilities in the NetBeans Platform, meet the requirements of the new concept functional interface in JDK 8. They're classes that have a single abstract method.

For example:

SaveCookie s = new SaveCookie() {
    public void save() {
        System.out.println("save to database...");

When a change is made somewhere, you can publish the above into the Lookup, causing the SaveAction to be enabled, which means the Save menu item, toolbar button, and keyboard shortcut can be invoked. When invoked, the System.out above is executed.

The Java editor in the IDE lets you convert the above to the below, using the "Use lambda expression" hint:

SaveCookie s = () -> {
    System.out.println("save to database...");

Cleaned up even further, it can be simplified to this, though it's kind of unlikely you're going to have one statement in the method:

SaveCookie s = () -> System.out.println("save to database...");

On the other hand, you could point to a method, where the actual save functionality is found:

SaveCookie s = () -> save();

Wednesday Feb 05, 2014

LambdaFicator - From Imperative to Functional Code through Automated Refactoring

The origins of the awesome Java hints for migrating to JDK 8 in NetBeans 8 comes from the tooling that came out of the research shown below!

Tuesday Feb 04, 2014

YouTube: Starting a Project with the Vaadin NetBeans Plugin

Get started with Vaadin in NetBeans IDE, today!

Monday Feb 03, 2014


BufferedReader.lines is kind of interesting, letting you turn a BufferedReader into a java.util.Stream in Java 8. Here's some small experiments.

Print out the number of lines in a file:

public static void main(String[] args) {
    try (BufferedReader reader = Files.newBufferedReader(
            StandardCharsets.UTF_8)) {
    } catch (IOException ex) {

Print out all the lines:

public static void main(String[] args) {
    try (BufferedReader reader = Files.newBufferedReader(
            StandardCharsets.UTF_8)) {
    } catch (IOException ex) {

Print out the longest line in a file:

public static void main(String[] args) {
    try (BufferedReader reader = Files.newBufferedReader(
            StandardCharsets.UTF_8)) {
    } catch (IOException ex) {

Sunday Feb 02, 2014

RedMonk at FOSDEM: Lies, Damned Lies, and Statistics

Imagine you switch on the TV and you're just in time to catch the start of the weather report. The reporter is smiling cheerfully into the camera, while saying:

"We haven't been able to measure weather statistics in the whole country. In fact, we don't really know exactly how large the country is. Nevertheless, that being said, based on the weather statistics that we did manage to get hold of, here is the state of the weather today."

That, honestly, is what happened at FOSDEM yesterday in a packed out (people standing in the aisles, sitting on the floor, lined up outside in the corridor) RedMonk session entitled "What a Long Strange Trip It's Been: The Past, Present and Future of Java". (Here's the abstract.)

Now, Steve O'Grady was perfectly frank in saying exactly what he said (and says it again in his blog article), "to be included in this analysis, a language must be observable within both GitHub and Stack Overflow." And that's really all that's been analyzed, i.e., GitHub and Stack Overflow. (As a corollary, you then end up in the endlessly hilarious and inherently unresolvable discussion about what it means that there are many questions on Stack Overflow about a language -- (a) that it is popular, (b) that it is complicated, (c) that it is badly documented, (d) combinations of the above, (e) something else.) OK, so then I think the title "The RedMonk Programming Language Rankings: January 2014" is really too heavy for the analysis that's been done and the content it provides, especially since by their own admission they haven't surveyed closed-source corporate software development, nor have any clue about how to do so. I'd have thought they'd have built up a database of software companies around the world, that they've built relationships with these companies, and that thanks to the relationships they've developed they're able to regularly poll these companies on the software (and languages and frameworks and libraries and IDEs) they're using. However, this turns out to be quite clearly not the case at all.

And I don't think it's a credible defence to say, "hey, I told you that we didn't analyze anything other than GitHub and Stack Overflow" because a lot of organizations take the analysis of RedMonk (and similar organizations, such as Forrester, where the difference is you have to pay for the analysis results and you get an impressively authenticated PDF, rather than a free blog entry) very seriously, in the same way that the weather reporter saying "the weather today has been sunny with blue skies" is taken seriously, because no one reads the small print that says "hey, we really don't know how large the country is and we possibly haven't visited most of it". In the case of the weather report, that would be absurd and they wouldn't have a particularly strong basis to exist if they said that.

Personally, I have no reason to make this point other than a concern that we really do need usable and independent research to be done on the ubiquity of programming languages (and frameworks and libraries and IDEs), since the conclusions reached by RedMonk favor Java, which is my personal favorite language, the one I have been supporting and promoting for the past 10 years.

In other words, I have nothing to gain by calling RedMonk's bluff. (I'd argue that even if you call your own bluff, it's still bluff.) They reached a conclusion I would have wanted them to reach: Java is not only alive, it is vibrant, self-sustaining, used everywhere by everyone in all manner of application development. However, in a year or so, RedMonk may do another scan (or analysis or whatever) of GitHub and Stack Overflow and then come to completely different conclusions. And they would be as invalid and as silly to base any kind of conclusion on than the ones they have most recently come up with and were presented at FOSDEM yesterday:

OK, thanks, Java is very much alive and vibrant and is used for things other than enterprise applications. (Later that day I met up with John Kostaras from NATO, where they work on a massive Java desktop system that manages European air defence, which of course is yet another example of corporate work being done in Java that falls outside of RedMonk's research. In fact, if RedMonk were to research the ubiquity of Java desktop development, they'd say the Java desktop is dead, but only because NATO and all the other massive enterprises in the defence, aerospace, and banking domain don't use GitHub and Stack Overflow.) The call to action at the end was that we should spread the word that Java is alive. Great. Everyone except maybe analysts, who may have been scanning (or analyzing or whatever the verb is) some other repository somewhere and come up with contradictory conclusions, already knew that.

I'm sure I wasn't the only one left with the question marks outlined above, several of the discussions at the end of the session more or less asked the same thing, and the response was more or less the same, kind of along these lines: "Hey, we don't know how large the programming world is, we have no way of knowing that, we have to do the best we can with the data that we can get".

If that is really the case then, in the first place, I really appreciate the honesty. In the second place, however, I'd suggest that analysts start actually building relationships with companies and developers at companies, rather than with repositories and on-line discussion forums. In the third place, it's invalid to draw any broad conclusions from this analysis. The worst thing that one can do is to say, essentially, "yes, the weather statistics are incomplete and, what's worse, we have no clue how incomplete, nevertheless, that having been said, the skies are sunny and blue".

As a final point, the first photo above of the "packed out RedMonk session", (with people standing in the aisles, sitting on the floor, lined up outside in the corridor,) might indicate that there was a massive interest in the state of Java and especially in what RedMonk had to say about that, which might further underline (a) that Java is very popular and (b) that RedMonk is taken very seriously. Both those things may, of course, be true. But the photo doesn't prove that at all because... pretty much all the rooms at FOSDEM were "packed out". It's a free conference with a massive turnout and... surprisingly small rooms.

Saturday Feb 01, 2014

FOSDEM: Constantin Drabo from FasoJUG

The highlight of my trip to FOSDEM 2014 in Brussels was meeting Constantin Drabo for the first time, active in the NetCAT team for years, from Burkina Faso, where he set up the FasoJUG sometime ago.

Constantin is, aside from being a NetBeans fan, a Fedora fan. Above we're at the Fedora booth and between us is Jaroslav, the Fedora product manager.

It was great to meet you at last, Constantin!

Friday Jan 31, 2014

Awesome Blogs (Part 1):

I'm starting a new occasional series where I highlight awesome blogs around the webiverse.

And a great one, what a pleasure to kick the series off with this one, is the brand new by Brett Ryan, from Melbourne, Australia.

  • In Migrating to JDK 8 with NetBeans, his first blog entry, he shows how to set up and use NetBeans 8 to refactor applications to use JDK 8. It is well written, clear, has lots of screenshots, and is just a great read.

  • In The Power of the Arrow he shows 5 examples of code where he starts with a pre-Java 8 construct and then moves it step by step via NetBeans 8 to a new Java 8 lambdafied style, with all the intermediate steps included, and motivations why making the move makes sense.

And he says cool things about NetBeans 8, such as:

"I started doing these by hand and then slapped myself, NetBeans' hints can do all this for me. With NetBeans generally a hint will appear, you smile and accept it, possibly modify, then another hint might appear so you grin and accept that too; before you know it you've taken 5 or more lines down to 1."

I'm really looking forward to seeing what's next in Brett's blog!

Thursday Jan 30, 2014

YouTube: "Smart Migration to JDK 8"

Don't know where to start with JDK 8? Here's a complete kit of info getting you in the right frame of mind for upgrading your code to leverage the Java 8 language changes.

Feedback is welcome!

Wednesday Jan 29, 2014

Slides: "Smart Migration to JDK 8"

A new slide deck for a screencast I am working on, planning to publish it tomorrow, on how to effectively migrate to JDK 8. I.e., you simply must have tools to do so, otherwise it's a nightmare.

All the slides with "Demo" on them are the points where I will switch into NetBeans IDE 8 and do a small demo.

Probably a lot of the above will change quite a bit. 

The slideshare location is here:

On a related note, take a look at this brilliant new article by Brett Ryan on migrating with NetBeans 8 to JDK 8:

Tuesday Jan 28, 2014

YouTube: NetBeans 8 Loves PrimeFaces (Part 2)

I think the news for users of Java EE 7, PrimeFaces, and Maven, yesterday, was pretty cool. A complete CRUD application in PrimeFaces can be generated from your database.

However, there's more! (With NetBeans, there's always more.) Rather than generating a complete CRUD app, you might simply want to create a PrimeFaces data table for your backend. Forget all the CRUD features. Instead, you only want to create a data table that accesses your database via all the Java EE 7 specifications. How to do this without scratching your head?

Here's how:

Monday Jan 27, 2014

YouTube: NetBeans 8 Loves PrimeFaces (Part 1)

Do you have less than 5 minutes to spend learning something really cool? And the cool thing is that if Maven, Java EE 7, and PrimeFaces are in your toolbox, then definitely NetBeans 8 should be too! The evidence is below, in a YouTube clip of less than 5 minutes.

Saturday Jan 25, 2014

Ad Designer on the NetBeans Platform (Part 2)

I added some new features to the visual designer I mentioned a few days ago. Now there is automatic synchronization from the view to the source (not yet from the source to the view), as well as better checking about where the drop can take place, i.e., the "logo" can only be in the header, etc, as well as a drop image, if the item can be dropped.

Video speaks better than words:

Source code:

Even though it's got HTML in the name, it's simply a visual designer for XML files. After that, the idea is that the XML files get converted to HTML.

Friday Jan 24, 2014

Air Traffic Standards Award for Barco Orthogon with NetBeans

In the air traffic management (ATM) domain, System Wide Information Management (SWIM) is a new open standard-based information infrastructure which will connect all ATM stakeholders, aircraft as well as all ground facilities. In the recently held annual SWIM innovation contest, where innovations in software related to this domain are highlighted, Barco Orthogon won the top prize, in one of the two categories, namely "applications", with a NetBeans Platform solution.

So, here we have one of the leaders in the standards-oriented air traffic management domain heavily using Java as its language, the NetBeans Platform as its application framework, and NetBeans IDE as its development environment. 

Below you can see part of the solution that won Barco Orthogon the prize, i.e., these are screenshots of Barco Orthogon's ODS Open Platform based solutions, which in turn are based on the NetBeans Platform. The images demonstrate the effect of two different sets of color resources, one for a "day view" and the other a "night view". Barco Orthogon won for the enhancements it constructed on top of the SWIM standards. For example, the connecting lines in the timeline view between the flight strips and the time scales have different colors because they indicate a status of the arrival sequence planning to the air traffic controller. In the night view, blue means "pre-sequenced" (preliminarily planned), white is "free" to be changed by the controller, while grey is "frozen", that is, in the very last phase of approach, and cannot be changed any more.

Great work, Barco Orthogon team!

Thursday Jan 23, 2014

Ad Designer on the NetBeans Platform (Part 1)

Here's a new NetBeans Platform sample that puts many typical things together and gets you jump started when creating some kind of designer.

The movie above is silent. It shows how to create a new XML file of the type managed by the application. It shows you can drag items into certain regions of the visual designer, i.e., items in the Header category of the Palette can only be dropped in the top of the three widgets, items in the Body category only in the middle, etc. Then right-click anywhere to serialize into the XML file.

Source code:

Even though it's got HTML in the name, it's simply a visual designer for XML files. After that, the idea is that the XML files get converted to HTML.

Now see part 2.

Wednesday Jan 22, 2014

Excluding Proposals from Code Completion in NetBeans 8

Finding the place in the Options window where you can list the classes you'd like to exclude from the Code Completion box is not easy.

Therefore, in NetBeans 8, you can exclude the classes you don't need right from within the Code Completion box. Below, notice the lightbulb at the far right in the currently selected item in the Code Completion box, which appears the second time you call up code completion:

Press Alt-Enter or click the lightbulb and now you see this:

Press Enter and the item is excluded from the Code Completion box because it has now been added here for you, i.e., instead of going all the way here, the class was registered here for you when you pressed Enter above:

NetBeans 8. Making your coding life simpler all the time.

Tuesday Jan 21, 2014

NetBeans IDE 8 in One Screenshot

I believe this image to represent the essence of the key features of NetBeans IDE 8.

For more:

Monday Jan 20, 2014

Options Window Color Analysis

So you're happily using JTattoo in your NetBeans Platform application. However, when you use the darker variations, such as "com.jtattoo.plaf.graphite.GraphiteLookAndFeel", you run into a problem. Though all the colors change as you'd expect... there's still the white background at the top of the Options window, as you can see below. 

That may seem like a small and insignificant problem. However, in the real world, Java and the NetBeans Platform are to be found in air traffic management and air traffic control systems, where the possibility of switching between a "day view" and a "night view", with all the related color updates, is not a "nice to have", but a "must".

So, the pesky white bar at the top of the Options window is a real problem in these real scenarios. A glaring white background is the very last thing you want in the Options window when the traffic controller has switched to "night view".

How to fix it? First, run the application from NetBeans IDE in Debug mode, open the Options window, and then click the orange camera button in the toolbar. Now a snapshot is made of the Options window and rendered in NetBeans IDE, where you can click on anything in the snapshot and see its related properties, such as the name of the panel where that white background is defined:

Then dig into the source code and find that panel. You now find that "Tree.background" is the relevant UIManager color for the white background in the Options window:

private static Color getTabPanelBackground() {
    if( isMetal || isNimbus ) {
        Color res = UIManager.getColor( "Tree.background" ); //NOI18N
        if( null == res )
            res = Color.white;
        return new Color( res.getRGB() );
    return Color.white;

Switch into your @OnStart annotated Runnable and use "Tree.background" as shown below:

public class Startable implements Runnable {
    public void run() {
        try {
            UIManager.put("Tree.background", Color.LIGHT_GRAY);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);

And here's the Options window again, gone is the white background at the top:

Don't like the light gray color I set above? Fine, change it to another color. The point is that you now have control over that color and you also know how to figure out similar problems next time.

Sunday Jan 19, 2014

JTattoo and NetBeans Platform

A first attempt at JTattoo usage in a NetBeans Platform application.

To achieve the above, create a new module that wraps JTattoo, and in a different module set a dependency on the JTattoo module and then include the following:

public class Startable implements Runnable {
    public void run() {
        try {
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);


Any NetBeans Platform developers using JTattoo out there, would be great to hear your opinions on it, and any tips and tricks.

Saturday Jan 18, 2014

Width of JavaScript Code Completion Box in NetBeans IDE

One thing I don't like about doing JavaScript in NetBeans IDE is the very wide code completion box, see below. Doesn't even fit in this blog, it's so wide, nor in the browser when you enlarge it below, without scrolling.

In NetBeans IDE 8, there's a new option to configure the width of the code completion box for JavaScript. You can see it below, "Code Completion Item Signature Char Width", which is set to 40 by default, but I prefer 10:

And now the code completion box is much friendlier:

And check out the cool Phaser code completion:

Note: This code completion configuration option is not in NetBeans IDE 8 Beta. It was added after that was released. You'll need a nightly build or wait for the final NetBeans IDE 8 release.


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.


« April 2014