Geertjan's Blog

  • March 19, 2014

One Click Open Sesame in NetBeans 8

Geertjan Wielenga
Product Manager

And my first plugin for NetBeans IDE 8 is done and published!

@andypotter on Twitter, and on the NetBeans users mailing list, wants to be able to open files by selecting them, rather than double-clicking. And the topic of double-clicking is something he is quite passionate about: "As nice as NetBeans is I will not use it if I must double-click every time I want to open a file into the editor."

Well, then, here's a plugin I created today that fixes that:


The code is as simple as this:

import org.netbeans.api.actions.Openable;
import org.openide.modules.OnStart;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.Utilities;
import org.openide.util.WeakListeners;
public class OneClickOpenSesame implements Runnable, LookupListener {
Lookup.Result openableResult = null;
public void run() {
openableResult = Utilities.actionsGlobalContext().lookupResult(Openable.class);
WeakListeners.create(LookupListener.class, this, openableResult));
public void resultChanged(LookupEvent le) {
for(Openable o : openableResult.allInstances()){

Someone reading the above code should now be thinking: "But wait a minute, doesn't this mean that someone who has selected a file, and thereby opened it, is never going to be able to close that file, unless selection changes to a different file?"

Indeed, yes, well done. The fatal flaw of this awesome plugin. But not a big deal. If you want to be able to close the file you opened, just select a folder (i.e., a folder doesn't have an Openable in its Lookup), after which you can close the file as usual.

Join the discussion

Comments ( 1 )
  • Dmitry Avtonomov Wednesday, March 26, 2014

    I didn't quite understand why wouldn't you be able to close a file? the o.open() should only called when selection changes, right?

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.