title: Custom Gradient Button - can't see Text
body: <p>I am making a custom button with a gradient effect. I am able to set the gradient effect but I can't see the text. Where am I going wrong?</p>
  
  <pre><code>class CustomButton extends JButton {   
      Color color1, color2;   
  
      public CustomButton(String text, Color color1, Color color2) {   
          super(text);   
          this.color1 = color1;   
          this.color2 = color2;   
          setOpaque(false);   
          setSize(new Dimension(450, 350));
          setForeground(Color.white);
          setText(text);
          setContentAreaFilled(false);
      }   
  
      protected void paintComponent(Graphics g) {    
          super.paintComponent(g);
          int width = getWidth();   
          int height = getHeight();   
  
          GradientPaint paint = new GradientPaint(0, 0, color1, width, height,
                  color2, true);
          Graphics2D g2d = (Graphics2D)g;
          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                  RenderingHints.VALUE_ANTIALIAS_ON);   
          Paint oldPaint = g2d.getPaint();
          g2d.setPaint(paint);
          g2d.fillRect(0, 0, width, height);
          g2d.drawString("Button 1", getWidth()/2, 10);
          g2d.setPaint(oldPaint);
      }   
  }  
  </code></pre>
  
  <p>NOTE: I allow the user to change the colors at run time. Based on the color that was changed to, I set the background accordingly.</p>