title: Centering a JLabel in a JPanel
body: <p>I have a panel derived from <code>JPanel</code>. I have a custom control derived from <code>JLabel</code>. I am attempting to center this custom <code>JLabel</code> on my panel.</p>
  
  <p>The only way I know to do this that will work is to use the a null layout (<code>setLayout(null)</code>) and then calculate the custom JLabel's <code>setLocation()</code> point so that it's in the right spot.</p>
  
  <p>The custom <code>JLabel</code> is physically moved from one panel to this panel in this app and I believe the location previously set in <code>setLocation</code> is affecting things.  However when I set it to (0,0) the component goes up into the upper left corner. </p>
  
  <p><code>BorderLayout</code> doesn't work because when only 1 component is provided and placed into <code>BorderLayout.CENTER</code>, the central section expands to fill all of the space.</p>
  
  <p>An example I cut and pasted from another site used <code>BoxLayout</code> and <code>component.setAlignmentX(Component.CENTER_ALIGNMENT)</code>. This didn't work either.</p>
  
  <p>Another answer mentioned overriding the panel's <code>getInset()</code> function (I think that's what it was called), but that proved to be a dead end.</p>
  
  <p>So far I'm working with a panel with a <code>GridBagLayout</code> layout and I include a <code>GridBagConstraints</code> object when I insert the custom <code>JLabel</code> into my panel. This is inefficient, though. Is there a better way to center the <code>JLabel</code> in my <code>JPanel</code>?</p>