Geertjan's Blog

  • October 5, 2007

NetBeans APIs Outside of the NetBeans Platform

Geertjan Wielenga
Product Manager
Jarda and I are in Budapest visiting a team of developers. Somewhere along the line, I think in the taxi on the way from the hotel to the site, he knocked together an application that uses the NetBeans APIs, without using the NetBeans Platform. In other words, there's no module here. Just a plain Java application. The end result is a file browser that looks as follows:

And this is the source structure of the application. Of course, take special note of the NetBeans API JAR files. You can easily get them from your distribution of NetBeans IDE and then simply add them to your own application:

By the way, Jarda added the beans from the org.openide.explorer.ExplorerManager JAR to the Palette, in order to be able to drag and drop the two views on the JFrame! He says that ideally the apisupport project should do that by default. Here's how it looks:

Here's FileNode.java:

import java.io.File;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
public final class FileNode extends AbstractNode {
private File file;
private FileNode(File f) {
super(new FileKids(f));
file = f;
public static Node files() {
AbstractNode n = new AbstractNode(new FileKids(null));
return n;
private static final class FileKids extends Children.Keys<File> {
File file;
public FileKids(File file) {
this.file = file;
protected void addNotify() {
if (file == null) {
File[] arr = File.listRoots();
if (arr.length == 1) {
arr = arr[0].listFiles();
} else {
File[] arr = file.listFiles();
if (arr != null) {
protected Node[] createNodes(File f) {
FileNode n = new FileNode(f);
return new Node[] { n };

Here's Explorer.java:

import org.openide.explorer.ExplorerManager;
public class Explorer extends javax.swing.JFrame implements ExplorerManager.Provider {
private ExplorerManager em;
/\*\* Creates new form Explorer \*/
public Explorer() {
em = new ExplorerManager();
/\*\* This method is called from within the constructor to
\* initialize the form.
\* WARNING: Do NOT modify this code. The content of this method is
\* always regenerated by the Form Editor.
private void initComponents() {
contextTreeView1 = new org.openide.explorer.view.ContextTreeView();
listView1 = new org.openide.explorer.view.ListView();
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
.add(contextTreeView1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
.add(listView1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, listView1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, contextTreeView1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE))
.add(23, 23, 23))

\* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Explorer().setVisible(true);
public ExplorerManager getExplorerManager() {
return em;
// Variables declaration - do not modify
private org.openide.explorer.view.ContextTreeView contextTreeView1;
private org.openide.explorer.view.ListView listView1;
// End of variables declaration

Finally, here's Main.java:

public class Main {
\* @param args the command line arguments
public static void main(String[] args) {

Join the discussion

Comments ( 13 )
  • Fabrizio Giudici Friday, October 5, 2007

    Well, this is really cool. Probably we shouldn't be suprised, but so far the only NetBeans APIs I've talked about a plain J2SE use was the Lookup and the Visual Library. I'm going to add this for my next talk about the platform.

  • Tom Wheeler Friday, October 5, 2007

    This is very interesting -- and timely, in light of the fact that I was discussing exactly this with some developers last week.

    What I wonder is, how much of the API can you use in a regular Swing application (i.e. not as modules)? While the code is pure Java, I think that there has got to be at least some places that are dependent on being loaded as module (classloader issues) or that depend on core infrastructure (for example, maybe the Dialogs API assumes that you're running within the WindowManager class instead of simply a JFrame.

  • Geertjan Sunday, October 7, 2007

    Hi Fabrizio and Tom. Cool to see interest in this. I'm sure thst this approach isn't possible for all NetBeans APIs, but for those where it does work, it is really cool.

  • Bob Namestka Friday, October 26, 2007

    Geertjan- this is a perfect way for desktop java developers to migrate from using pure Swing to using the Netbeans platform in small incremental steps. Plunging into desktop app development based on the Netbeans platform is still a bit daunting for mere mortals even with excellent resources like your blog and your book. Thanks.

  • Geertjan Friday, October 26, 2007

    I could not agree with you more, Bob!

  • George L. Wednesday, February 23, 2011

    Could someone give me the project ready? please

    I have problems with the code,I have no idea why.

  • Geertjan Wielenga Thursday, February 24, 2011

    Can you give even a small clue about what's going wrong? Otherwise you will not get any help, not from me anyway.

  • Norman Thursday, June 5, 2014

    Hi Geertjan, great article. I wonder if it is possible to also use the NetBeans Window System (TopComponent) outside the NetBeans platform, as we already have our own platform for a Swing-based desktop application. We are currently using the JIDE Docking Framwork, but we need to get rid of it. Can't find anything about this in the net.

  • Geertjan Friday, June 6, 2014

    Norman, sent you an e-mail, hope you got it.

  • Dan Fabrizio Wednesday, October 8, 2014

    I would be interested in using the Netbeans Window System outside the Netbeans platform too.

    Is that possible?


  • Geertjan Thursday, October 9, 2014

    I'd advise against it. I haven't seen any applications that make use only of the NetBeans Window System. Sounds a bit like a misunderstanding of the Window System as well as the NetBeans Platform as a whole, to want to do that. Search for 'Swing docking frameworks' and you'll probably find other docking frameworks that are not tied to a comprehensive application framework like the NetBeans Platform.

  • Robert Lemke Thursday, December 4, 2014

    Hi Geertjan,

    Thank you for your responses.

    I have worked through your "Netbeans Visual Library Tutorial" and find it extremely helpful. My need is to have the palette functionality, but outside the IDE, as discussed in the article titled "Netbean API's outside of the Netbeans Platform". This latter example uses a browser as an example. Now to the questions:

    1. Is there a tutorial on using the palette outside the IDE. If not, can the tutorial on using netbeans API's outside the Netbeans platform be used to develop the palette requirement, given the palette API qualifies for external use?

    Many thanks for your contributions,

    Kind regards,

    Dr. Robert Lemke

  • Geertjan Thursday, December 4, 2014

    No, I'm sorry, the Palette cannot be used outside of the NetBeans Platform. Too many dependencies on various NetBeans APIs. I recommend you either commit to the NetBeans Platform or recreate palette functionality in your own application from scratch.

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