NullPointerException in FontDesignMetrics$MetricsKey.init when using Netbeans Visual Library

If you’re getting a NullPointerException stacktrace like the one below while using the Netbeans Visual Library to create your own GraphScene, check that your adding your widgets propertly to scene. A good idea is to use LayerWidgets, declaring them in the constructor of your GraphScene: mainLayer = new LayerWidget(this); addChild(mainLayer); connectionLayer = new LayerWidget(this); addChild(connectionLayer); and then add the widgets to those layers in attachNodeWidget and attachEdgeWidget: @Override protected Widget attachNodeWidget(String node) { LabelWidget w = new LabelWidget(this, node); w.setBorder(BORDER4); w.getActions().addAction(createSelectAction()); w.getActions().addAction(createObjectHoverAction()); w.getActions().addAction(ActionFactory.createMoveAction()); this.mainLayer.addChild(w); return w; } @Override protected Widget attachEdgeWidget(String edge) { ConnectionWidget w = new ConnectionWidget(this); w.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED); this.connectionLayer.addChild(w); return w; } The stacktrace: ...

April 30, 2009

Opening Favorites window at startup in a Netbeans Platform Application

After learning about the Favorites window in the NetBeans Platform Quick Start. I wanted to use it in an application of my own. This easy task became more difficult that I though because I was getting random results, sometimes after a clean build I got the Favorites window open and sometimes not. But let’s start from the beginning, I put my hands at work, it was just a matter of adding the Favorites module to the Netbeans Platform Application (app’s properties ⇒ Libraries ⇒ Platform Modules ⇒ platform9 ⇒ Favorites) and edit one of my modules layer.xml to override Windows2/Modes/explorer/favorites.wstcref. Just go to Important Files ⇒ XML Layer ⇒ this layer in context ⇒ Windows2 ⇒ Modes ⇒ explore ⇒ favorites.wstcref and replace ...

April 28, 2009

How to hide/remove the Save, Undo and Redo buttons on the Toolbar (Netbeans Platform)

The default Netbeans Platform Application generated by the Netbeans IDE wizard has the Save, Undo and Redo button showing up in the toolbar by default. Since my applications doesn’t have anything to save I decided to hide those buttons. I turns out that remove them is really simple, I knew that I had to fiddle with the layer.xml file and hide something but I didn’t know exactly what. At the end I found the solution buried in this A NetBeans Platform Sample and Tutorial. ...

March 8, 2009