示例#1
0
  @Override
  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x, y, width, height);
    int w = getWidth() - (SHADOW_SIZE - 2) * 2;
    int h = getHeight() - (SHADOW_SIZE - 2) * 2;
    int arc = 15;
    int shadowSize = SHADOW_SIZE;
    shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = shadow.createGraphics();

    if (active) {
      g2.setColor(new Color(243, 238, 39, 150));
    } else {
      g2.setColor(Color.WHITE);
    }

    g2.setColor(Color.WHITE);
    g2.fillOval(0, 0, w, h);
    g2.dispose();
    ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK);
    shadow = renderer.createShadow(shadow);
    g2 = shadow.createGraphics();
    g2.setColor(Color.GRAY);
    g2.setComposite(AlphaComposite.Clear);
    g2.fillOval(shadowSize, shadowSize, w, h);
    g2.dispose();
  }
  // Method used to paint shadow around the panel
  @Override
  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x, y, width, height);

    int w = getWidth() - 68;
    int h = getHeight() - 68;
    int arc = 30;
    int shadowSize = 20;

    shadow = ImagesUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = shadow.createGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRoundRect(0, 0, w, h, arc, arc);
    g2.dispose();

    ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK);
    shadow = renderer.createShadow(shadow);

    g2 = shadow.createGraphics();
    // The color does not matter, red is used for debugging
    g2.setColor(Color.RED);
    g2.setComposite(AlphaComposite.Clear);
    g2.fillRoundRect(shadowSize, shadowSize, w, h, arc, arc);
    g2.dispose();

    if (shadow != null) {
      int xOffset = (shadow.getWidth() - w) / 2;
      int yOffset = (shadow.getHeight() - h) / 2;
      g2.drawImage(shadow, x - xOffset, y - yOffset, null);
    }
  }