Centralized Search Action

Here's how to show the Quick Search textfield in a dialog by clicking a menu item.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JPanel;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.awt.Actions;
import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.Presenter;

@ActionID(
        category = "Edit",
        id = "org.bla.SearchAction"
)
@ActionRegistration(
        displayName = "#CTL_SearchAction"
)
@ActionReference(path = "Menu/File", position = 1300)
@Messages("CTL_SearchAction=Search")
public final class SearchAction implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        JPanel panel = new JPanel(new BorderLayout());
        Action qs = Actions.forID("Edit", "org.netbeans.modules.quicksearch.QuickSearchAction");
        Component quickSearchToolbarItem = ((Presenter.Toolbar) qs).getToolbarPresenter();
        panel.add(quickSearchToolbarItem, BorderLayout.CENTER);
        DialogDescriptor dd = new DialogDescriptor(panel, "Search");
        DialogDisplayer.getDefault().notify(dd);
    }
}
Comments:

Do you have an example of making this appear in any TopComponent, like it does with most editors? And/or an example of integrating it? I have a lot of TopComponent classes that simply contain tables. It'd be nice to do a search and highlight the row or cell where a match is found.

Posted by Michael Bishop on February 11, 2014 at 07:07 AM PST #

https://blogs.oracle.com/geertjan/entry/place_the_quicksearch_component_anywhere

Hope it helps.

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

Yes, absolutely. I keep forgetting that quick search isn't the Find UI that I'm thinking of. Still, this could work. Thanks for the link.

Posted by Michael Bishop on February 11, 2014 at 09:30 PM PST #

Hello Geertjan,

Thank You for your blog on Netbeans platform Application.

Please tell me how can I use quick search component without using toolbar , because I didn't require toolbar in my application and it's taking huge space in main window. I want to use quick search component. in custom dialog descriptor as you did the same.

http://forums.netbeans.org/viewtopic.php?p=156697#156697

Kind Regards,
Gourav Garg

Posted by guest on April 11, 2014 at 12:35 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today