5151import java .util .function .Function ;
5252import java .util .stream .Collectors ;
5353
54+ import javax .swing .BorderFactory ;
5455import javax .swing .Box ;
5556import javax .swing .BoxLayout ;
5657import javax .swing .DefaultListModel ;
6162import javax .swing .JLabel ;
6263import javax .swing .JList ;
6364import javax .swing .JPanel ;
65+ import javax .swing .JRootPane ;
6466import javax .swing .JScrollPane ;
6567import javax .swing .JSplitPane ;
6668import javax .swing .JTextField ;
@@ -304,19 +306,16 @@ public SwingSearchPanel() {
304306
305307 final JPanel detailsPane = new JPanel ();
306308 final JLabel detailsTitle = new JLabel ();
307- detailsTitle .setHorizontalAlignment (SwingConstants .CENTER );
309+ detailsTitle .setHorizontalAlignment (SwingConstants .LEFT );
308310 final JPanel detailsProps = new JPanel ();
309311 final JPanel detailsButtons = new JPanel ();
310312 detailsButtons .setLayout (new BoxLayout (detailsButtons , BoxLayout .X_AXIS ));
311- detailsTitle .setAlignmentX (0.5f );
312- detailsProps .setAlignmentX (0.5f );
313- detailsButtons .setAlignmentX (0.5f );
314313
315- detailsPane .setLayout (new BoxLayout (detailsPane , BoxLayout .Y_AXIS ));
314+ detailsPane .setLayout (new MigLayout ("wrap" ,"[grow]" , "[][grow][]" ));
315+ detailsPane .setBorder (BorderFactory .createEmptyBorder (PAD , PAD , PAD , PAD ));
316316 detailsPane .add (detailsTitle );
317- detailsPane .add (detailsProps );
318- detailsPane .add (detailsButtons );
319- detailsPane .add (Box .createVerticalGlue ());
317+ detailsPane .add (detailsProps , "grow,span" );
318+ detailsPane .add (detailsButtons , "grow" );
320319
321320 resultsList .addListSelectionListener (lse -> {
322321 if (lse .getValueIsAdjusting ()) return ;
@@ -341,40 +340,54 @@ public SwingSearchPanel() {
341340 // populate details pane
342341 detailsTitle .setText ("<html><h2>" + result .name () + "</h2>" );
343342 detailsProps .removeAll ();
344- detailsProps .setLayout (new MigLayout ("fillx, wrap 2" , "[200px|pref ]" , "pref" ));
343+ detailsProps .setLayout (new MigLayout ("wrap 2, ins 0 " , "[123!][grow ]" , "pref" ));
345344 result .properties ().forEach ((k , v ) -> {
346345 if (k == null ) {
347346 final JTextPane textPane = new JTextPane ();
348347 textPane .setContentType ("text/html" );
349348 textPane .setText (v );
350- detailsProps .add (textPane , "span 2" );
349+ textPane .setMargin (null );
350+ textPane .setEditable (false );
351+ textPane .setOpaque (false );
352+ detailsProps .add (textPane , "span 2, grow" );
351353 }
352354 else {
353355 final JLabel keyLabel = new JLabel ("<html>" +
354- "<strong style=\" color: gray; padding-right: 5px\" >" + k +
355- " </strong>" , SwingConstants .RIGHT );
356- detailsProps .add (keyLabel );
356+ "<strong style=\" color: gray;\" >" + k +
357+ " </strong>" );
358+ keyLabel .setHorizontalAlignment ( RIGHT );
359+ detailsProps .add (keyLabel , "grow" );
357360 final JTextField valueField = new JTextField ();
358361 valueField .setText (v );
359362 valueField .setEditable (false );
360363 valueField .setBackground (null );
361364 valueField .setBorder (null );
362- detailsProps .add (valueField );
365+ detailsProps .add (valueField , "grow" );
363366 }
364367 });
365368 detailsButtons .removeAll ();
366369 final List <SearchAction > actions = searchService .actions (result );
367- actions .forEach (action -> {
370+ boolean first = true ;
371+ for (SearchAction action : actions ){
372+ if (!first ){
373+ detailsButtons .add (Box .createHorizontalStrut (5 ));
374+ }
368375 final JButton button = new JButton (action .toString ());
369376 button .addActionListener (ae -> {
370377 action .run ();
371378 if (action .willCloseSearch ()){
372- reset ();
379+ reset ();
373380 }
374381 });
375382 button .addKeyListener (new SearchBarKeyAdapter ());
376383 detailsButtons .add (button );
377- });
384+ if (first ){
385+ JRootPane rootPane = this .getRootPane ();
386+ rootPane .setDefaultButton (button );
387+ detailsButtons .add (Box .createHorizontalGlue ());
388+ first = false ;
389+ }
390+ }
378391 }
379392 });
380393
0 commit comments