title: What is best way to center objects in JPanel horizontally and vertically
body: <p>I'm trying to add a panel p1 on the left on the panelMain. Since the objects are not center vertically, I tried to add p1 on p2, which has BorderLayout. I guess this is not a good way but it doesn't even work. I didn't use GridLayout because I don't want the objects to fill up the whole JPanel.</p>
  
  <pre><code>JPanel panelMain = new JPanel( new BorderLayout() );
  
  JPanel p1 = new JPanel( new FlowLayout(FlowLayout.CENTER) );
  panelText.setPreferredSize( new Dimension( 250, frame.getHeight() ) );
  panelText.add( new JLabel( "Name:", SwingConstants.RIGHT) );
  panelText.add( new JTextField( "First Last:", 15 ) );
  panelText.add( new JLabel( " Tel:", SwingConstants.RIGHT) );
  panelText.add( new JTextField( "000-000-0000", 15) );
  
  JPanel p2 = new JPanel( new BorderLayout() );
  p2.add( p1, BorderLayout.CENTER );
  
  panelMain.add( p2,BorderLayout.WEST );
  </code></pre>