Place the quicksearch component anywhere you like (Part 2)

The NetBeans Platform comes with a pluggable filter component. Nicklas Löf explained in his blog sometime ago how to place that component anywhere you like. Today I wondered if the Matisse GUI Builder could be used to layout the location of the component.

I came up with a simple trick. Drag and drop a JPanel from the Palette onto your TopComponent:

Then use the code from Nicklas' blog, linked above, to retrieve the component via your layer entry (which is also explained by Nicklas)... but add the component to the JPanel that you have just put into your TopComponent:

Action action = Utilities.actionsForPath("QuickSearchShadow").get(0);
Component quickSearchToolbarItem = ((Presenter.Toolbar) action).getToolbarPresenter();
myPanel.add(quickSearchToolbarItem, BorderLayout.CENTER);

The above code is in the constructor of my TopComponent. Now you can drag the JPanel around in your TopComponent in the Matisse GUI Builder, thus being able to layout the exact design of your TopComponent, treating the filter component like any other Swing component, which of course is exactly what it is, with this result, for example:

Then plug your own filters into the component, using its API. Simple solution, right?


The first line should rather be:

Action action = (Action) FileUtil.getConfigObject("Actions/Edit/org-netbeans-modules-quicksearch-QuickSearchAction.instance");

Posted by Jesse Glick on September 26, 2011 at 06:45 AM PDT #

Yes, but "FileUtil.getConfigObject" is from 7.1 onwards.

Posted by guest on September 26, 2011 at 07:24 AM PDT #

Actions.forID("Edit", "org.netbeans.modules.quicksearch.QuickSearchAction");

Posted by Geertjan on February 11, 2014 at 07:40 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

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.


« March 2015