X

Geertjan's Blog

  • March 2, 2014

Quick Search Embedded East

Geertjan Wielenga
Product Manager
The requirement is to have an Action that shows the Quick Search field. One approach was described here and here's another one.

Here's how.

public final class SearchAction implements ActionListener {
JPanel panel = new JPanel();
@Override
public void actionPerformed(ActionEvent e) {
JButton closeButton = createButton();
Action qs = Actions.forID(
"Edit",
"org.netbeans.modules.quicksearch.QuickSearchAction");
Component quickSearchToolbarItem
= ((Presenter.Toolbar) qs).getToolbarPresenter();
panel.add(quickSearchToolbarItem);
panel.add(closeButton);
Frame mainWindow = WindowManager.getDefault().getMainWindow();
Container contentPane
= ((JRootPane) mainWindow.getComponents()[0]).getContentPane();
contentPane.add(BorderLayout.EAST, panel);
mainWindow.validate();
}
private JButton createButton() {
JButton closeButton = new JButton();
closeButton.setText("x");
closeButton.setFocusPainted(false);
closeButton.setMargin(new Insets(0, 0, 0, 0));
closeButton.setContentAreaFilled(false);
closeButton.setBorderPainted(false);
closeButton.setOpaque(false);
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Frame mainWindow = WindowManager.getDefault().getMainWindow();
Container contentPane
= ((JRootPane) mainWindow.getComponents()[0]).getContentPane();
panel.removeAll();
contentPane.remove(panel);
mainWindow.validate();
}
});
return closeButton;
}
}

Be the first to comment

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