title: Center alignment of buttons in JPanel
body: <p>How do I align the buttons (S, S, D &amp; D and A, U, D &amp; d) to the middle of the panels (the blue and red)? The panels can grow (height not width), but the buttons should stay in the middle and keep the same size. So GridLayout is out.</p>
  
  <pre><code>
  
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTable;
  
      import java.awt.Dimension;
      import java.awt.FlowLayout;
      import java.awt.GridLayout;
  
      import javax.swing.JButton;
      import java.awt.BorderLayout;
      import java.awt.Color;
  
  
      public class TestFrame extends JFrame {
          /**
           * 
           */
          private static final long serialVersionUID = 5671798241966272024L;
  
          public TestFrame() {
  
              FlowLayout layout = new FlowLayout();
  
              JButton moveUpButton = new JButton("U");
              JButton moveAllUpButton = new JButton("A");
  
              JButton moveDownButton = new JButton("D");
              JButton moveAllDownButton = new JButton("D");
  
              JButton selectButton = new JButton("S");
              JButton selectAllButton = new JButton("S");
  
              JButton deselectButton = new JButton("D");
              JButton deselectAllButton = new JButton("D");
  
  
              setSize(600, 400);
  
              getContentPane().setLayout(new GridLayout());
  
  
              JPanel selectButtonsPanel = new JPanel();
              selectButtonsPanel.setBackground(Color.BLUE);
  
              selectButtonsPanel.setLayout(layout);
              selectButtonsPanel.setPreferredSize(new Dimension(50, 0));
              selectButtonsPanel.add(selectAllButton);
              selectButtonsPanel.add(selectButton);
              selectButtonsPanel.add(deselectButton);
              selectButtonsPanel.add(deselectAllButton);
  
              JPanel moveButtonsPanel = new JPanel(layout);
              moveButtonsPanel.setBackground(Color.RED);
              moveButtonsPanel.setLayout(layout);
              moveButtonsPanel.setPreferredSize(new Dimension(50, 0));
              moveButtonsPanel.add(moveAllUpButton);
              moveButtonsPanel.add(moveUpButton);
              moveButtonsPanel.add(moveDownButton);
              moveButtonsPanel.add(moveAllDownButton);
  
  
              JPanel sourcePanel = new JPanel ();
              sourcePanel.setLayout(new BorderLayout());
              sourcePanel.add(new JTable(), BorderLayout.CENTER);
              sourcePanel.add(selectButtonsPanel, BorderLayout.EAST);
  
  
              JPanel destinationPanel = new JPanel ();
              destinationPanel.setLayout(new BorderLayout());
              destinationPanel.add(new JTable(), BorderLayout.CENTER);
              destinationPanel.add(moveButtonsPanel, BorderLayout.EAST);
  
  
              getContentPane().add (sourcePanel);
              getContentPane().add(destinationPanel);
  
  
          }
  
      }
  
  </code></pre>