public static Color getBackgroundColor(Component component) {
    if (component == null) return null;

    if (component instanceof BackgroundPainter) {
      ComponentPainter painter = ((BackgroundPainter) component).getComponentPainter();

      if (painter != null) {
        Color color = painter.getColor(component);

        if (color != null) return color;
      }
    }

    return component.isOpaque()
        ? component.getBackground()
        : getBackgroundColor(component.getParent());
  }
Ejemplo n.º 2
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (painter != null) {
      Shape shape = getShape();

      if (shape != null) {
        Shape clip = g.getClip();
        g.clipRect(
            shapedInsets.left,
            shapedInsets.top,
            getWidth() - shapedInsets.left - shapedInsets.right,
            getHeight() - shapedInsets.top - shapedInsets.bottom);
        ((Graphics2D) g).clip(shape);
        painter.paint(
            this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip);
        g.setClip(clip);
      } else
        painter.paint(
            this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip);
    }
  }