title: How do I make my custom bitmap button field use a transparent background?
body: <p>I have a custom bitmap buttonfield that completely works, however, the background behind the image is showing a white rectangle. I've found where it makes the color white, but I cannot figure out how to make it completely transparent. Any ideas? I'm programming in blackberry java JDE 5.0</p>
  
  <p>FYI The button image is a rounded corner png file that uses transparency on the corners</p>
  
  <p>Code:</p>
  
  <pre><code>public class BitmapButtonField extends Field 
  {
  
      Bitmap _currentPicture;
      private Bitmap _onPicture;
      Bitmap _offPicture;
      private int id;
  
  
      public BitmapButtonField (Bitmap  onImage, Bitmap offImage)
      {
         super(Field.FOCUSABLE|Field.FIELD_HCENTER);
         _offPicture = offImage;
         _onPicture = onImage;
         _currentPicture = _onPicture;
      }
  
      public void setButtonImage (Bitmap onImage, Bitmap offImage)
      {
          _offPicture = offImage;
          _onPicture = onImage;
          _currentPicture = _onPicture;
       }
  
      public void setButtonId(int id)
      {
          this.id = id;
      }
      public int getButtonId()
      {
          return this.id;
      }    
  
      public int getPreferredHeight()
      {
          return _onPicture.getHeight();
      }
  
  
      public int getPreferredWidth()
      {
          return _onPicture.getWidth();
      }
  
      protected void onFocus(int direction)
      {
          _currentPicture = _offPicture;
         invalidate();
      }
  
      protected void onUnfocus()
      {
          _currentPicture = _onPicture;
         invalidate();
      }
  
      protected void drawFocus(Graphics g, boolean on)
      {        
          g.setBackgroundColor(Color.BLACK);
      }
  
      protected void layout(int width, int height) 
      {
          setExtent(Math.min( width, getPreferredWidth()), Math.min( 
                              height, getPreferredHeight()));
      }
  
      protected void paintBackground(Graphics g) {
            int prevColor = g.getColor();
            int prevAlpha = g.getGlobalAlpha();
            g.setColor(Color.YELLOW);
            g.setGlobalAlpha(0);
            g.fillRect(0, 0, getWidth(), getHeight()); // or g.getClippingRect()
            g.setColor(prevColor);
            g.setGlobalAlpha(prevAlpha);
          }
  
          protected void paint (Graphics graph){
  
          graph.setColor(Color.WHITE);
          //super.paint(graph);
  
          graph.fillRect(0, 0, getWidth(), getHeight());
          graph.drawBitmap(0, 0, getWidth(), getHeight(), 
                               _currentPicture, 0, 0);    
          }
  
  
      protected boolean navigationClick(int status, int time)
      {
          fieldChangeNotify(0);
          return true;
      }
  
      public boolean keyChar(char key, int status, int time)
      {
          if (key == Characters.ENTER)
          {
              fieldChangeNotify(0);
              return true;
          }
          return false;
      }
  }
  </code></pre>