3737import java .awt .Font ;
3838import java .awt .GridLayout ;
3939import java .awt .Window ;
40+ import java .awt .event .ActionListener ;
4041import java .awt .event .FocusEvent ;
4142import java .awt .event .FocusListener ;
4243import java .awt .event .KeyAdapter ;
7172import javax .swing .JTextArea ;
7273import javax .swing .JTextField ;
7374import javax .swing .JTextPane ;
75+ import javax .swing .JToolBar ;
7476import javax .swing .ScrollPaneConstants ;
7577import javax .swing .SwingUtilities ;
7678import javax .swing .UIManager ;
@@ -111,7 +113,7 @@ public class SwingSearchBar extends JTextField {
111113 private static final int PAD = 5 ;
112114
113115 private final DocumentListener documentListener ;
114- private final JButton closeButton ;
116+ private final JToolBar buttons ;
115117
116118 @ Parameter
117119 private SearchService searchService ;
@@ -180,13 +182,8 @@ public void focusLost(final FocusEvent e) {
180182 }
181183 });
182184
183- closeButton = new JButton ("<html><span style=\" font-size: 2.5em\" >\u2612 </span>" );
184- closeButton .setToolTipText ("Close the search results pane" );
185- closeButton .setBorder (null );
186- closeButton .addActionListener (ae -> {
187- reset ();
188- loseFocus ();
189- });
185+ buttons = new JToolBar ();
186+ buttons .setFloatable (false );
190187 }
191188
192189 /** Called externally to bring the search bar into focus. */
@@ -197,6 +194,12 @@ public void activate() {
197194 });
198195 }
199196
197+ /** Closes the search results pane. */
198+ public void close () {
199+ reset ();
200+ loseFocus ();
201+ }
202+
200203 /** Gets the maximum number of results per search category. */
201204 public int getResultLimit () {
202205 return resultLimit ;
@@ -218,6 +221,16 @@ public void setMouseoverEnabled(final boolean mouseoverEnabled) {
218221 this .mouseoverEnabled = mouseoverEnabled ;
219222 }
220223
224+ /** Adds a button to the search pane's toolbar. */
225+ public void addButton (final String label , final String tooltip ,
226+ final ActionListener action )
227+ {
228+ final JButton button = new JButton (label );
229+ if (tooltip != null ) button .setToolTipText (tooltip );
230+ if (action != null ) button .addActionListener (action );
231+ buttons .add (button );
232+ }
233+
221234 // -- Utility methods --
222235
223236 // TODO: Move this method to PluginService.
@@ -536,7 +549,7 @@ public void mouseMoved(final MouseEvent e) {
536549 }
537550 });
538551
539- detailsPane .add (closeButton , "pos n 0 100% n" );
552+ detailsPane .add (buttons , "pos n 0 100% n" );
540553 detailsPane .add (detailsTitle , "growx, pad 0 0 0 -20" );
541554 detailsPane .add (detailsScrollPane , "growx, hmin 0, wmin 0" );
542555 detailsPane .add (detailsButtons , "growx" );
0 commit comments