Image image = null; if(imageCache.containsKey(key)) { image = (Image)imageCache.get(key); } else { image = createTransparentImage(key); if(image != null) { imageCache.put(key, image); } }  gc.drawImage(image, 0, 0);
gc.drawImage(getTransparentImage(key), 0, 0);
  private void paintControl(GC gc) {    this.gc = gc;    // Text Mode!    if (imageDataHash.get("") == null) {      int textHeight = gc.getFontMetrics().getHeight();      // If we have some kind of background, we need to deal with printing the      // text button on top with some kind of transparency.  Which is what      // this code does.      if (textBackground != null) {        Image tempImage = new Image(this.getDisplay(), textBackground            .getImageData());        GC tempGC = new GC(tempImage);        if (isEnabled) {          if (isMouseOver) {            tempGC.drawRectangle(0, 0, textBackground.getImageData().width - 2,                textBackground.getImageData().height - 2);          }        }        else {          tempGC.setForeground(this.getDisplay().getSystemColor(              SWT.COLOR_DARK_GRAY));        }        if (isPressed) {          int length = getStringLength(pressedText);          int x = (textBackground.getImageData().width - length) / 2;          int y = (textBackground.getImageData().height - textHeight) / 2;          tempGC.drawText(pressedText, x, y, true);        }        else {          int length = getStringLength(normalText);          int x = (textBackground.getImageData().width - length) / 2;          int y = (textBackground.getImageData().height - textHeight) / 2;          tempGC.drawText(normalText, x, y, true);        }        gc.drawImage(tempImage, 0, 0);        tempGC.dispose();        tempImage.dispose();      }      // If we have no background, then we can just draw right onto the GC, but      // we need to cut out anything that was previously there.      else {        if (isEnabled) {          if (isMouseOver) {            gc.drawRectangle(0, 0, this.getBounds().width - 2,                this.getBounds().height - 2);          }        }        else {          gc.setForeground(this.getDisplay()              .getSystemColor(SWT.COLOR_DARK_GRAY));        }        if (isPressed) {          int length = getStringLength(pressedText);          int x = (this.getBounds().width - length) / 2;          int y = (this.getBounds().height - textHeight) / 2;          gc.drawText(pressedText, x, y, true);        }        else {          int length = getStringLength(normalText);          int x = (this.getBounds().width - length) / 2;          int y = (this.getBounds().height - textHeight) / 2;          gc.drawText(normalText, x, y, true);        }      }    }    else {      // Graphic mode!      // If the user has the mouse button held down over the button, display      // the appropriate image.      String key;      if (isActive) {        if (isPressed) {          key = "pressed.active";        }        else {          key = "active";        }      }      else {        // If the mouse is over the button        if (isMouseOver) {          // If the mouse is pressed, display the pressed Hot Image          if (isPressed) {            key = "pressed.hot";            if(!imageDataHash.containsKey(key)) {                key = "pressed";            }          }          // Otherwise, display the normal hot image          else {            key = "hot";          }        }        // If the mouse isn't over the image ...        else {          // If the button is pressed, show the pressed image          if (isPressed) {            key = "pressed";          }          // Otherwise, just show the normal state          else {            key = "";          }        }      }      try {        Image image = null;        if(imageCache.containsKey(key)) {            image = (Image)imageCache.get(key);        }        else {            image = createTransparentImage(key);             if(image != null) {                imageCache.put(key, image);            }        }                gc.drawImage(image, 0, 0);        //image.dispose();      }      catch (Exception ex) {        ex.printStackTrace();      }    }  }