Place the quicksearch component anywhere you like (Part 2)
By Geertjan on Sep 26, 2011
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?