Good day. There is a class that draws a shadow. Everything is fine under Windows, but in MAC OS in java 6 it draws as it should, and java 7 and 8 draws incorrectly. What could be the problem? Thanks in advance.

import com.sun.awt.AWTUtilities; import javax.swing.*; import java.awt.*; public class TestFrame extends JFrame { public static void main(String[] args) { new TestFrame(); } public TestFrame() { setUndecorated(true); setSize(new Dimension(500, 500)); setLocationRelativeTo(null); AWTUtilities.setWindowOpaque(this, false); DropShadowPanel panel = new DropShadowPanel(new Color(0, 0, 0, 0.3f), 25, 0); panel.setBackground(new Color(0, 0, 0, 0)); panel.setPreferredSize(new Dimension(400, 400)); getContentPane().add(panel); setVisible(true); } } 
 import javax.swing.*; import java.awt.*; import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; public class DropShadowPanel extends JPanel { private static Color shadowColor; private static int shadowSize; private static int shadowDistance; public DropShadowPanel() { this(Color.black); } public DropShadowPanel(Color shadowColor) { this(shadowColor, 25); } public DropShadowPanel(Color shadowColor, int shadowSize) { this(shadowColor, shadowSize, 0); } public DropShadowPanel(Color shadowColor, int shadowSize, int shadowDistance) { this.shadowColor = shadowColor; this.shadowSize = shadowSize; this.shadowDistance = shadowDistance; } @Override protected void paintComponent(Graphics gr) { super.paintComponent(gr); setBackground(new Color(0, 0, 0, 0)); Graphics2D g = (Graphics2D) gr; Rectangle2D r = new Rectangle2D.Double(25, 25, 300, 300); g.setColor(Color.BLUE); g.fill(r); if (shadowSize > 0) { draw(g, r, shadowSize); } } private static void draw(Graphics2D g, Rectangle2D r, double s) { Color c0 = shadowColor; //c1 - full opacity color Color c1 = new Color(255, 255, 255, 0); double x0 = r.getMinX(); double y0 = r.getMinY(); double x1 = r.getMaxX(); double y1 = r.getMaxY(); double w = r.getWidth(); double h = r.getHeight(); // Left g.setPaint(new GradientPaint( new Point2D.Double(x0, y0), c0, new Point2D.Double(x0 - s, y0), c1)); g.fill(new Rectangle2D.Double(x0 - s, y0, s, h)); // Right g.setPaint(new GradientPaint( new Point2D.Double(x1, y0), c0, new Point2D.Double(x1 + s, y0), c1)); g.fill(new Rectangle2D.Double(x1, y0, s, h)); // Top g.setPaint(new GradientPaint( new Point2D.Double(x0, y0), c0, new Point2D.Double(x0, y0 - s), c1)); g.fill(new Rectangle2D.Double(x0, y0 - s, w, s)); // Bottom g.setPaint(new GradientPaint( new Point2D.Double(x0, y1), c0, new Point2D.Double(x0, y1 + s), c1)); g.fill(new Rectangle2D.Double(x0, y1, w, s)); float fractions[] = new float[] { 0.0f, 1.0f }; Color colors[] = new Color[] { c0, c1 }; // Top Left g.setPaint(new RadialGradientPaint( new Rectangle2D.Double(x0 - s, y0 - s, s + s, s + s), fractions, colors, CycleMethod.NO_CYCLE)); g.fill(new Rectangle2D.Double(x0 - s, y0 - s, s, s)); // Top Right g.setPaint(new RadialGradientPaint( new Rectangle2D.Double(x1 - s, y0 - s, s + s, s + s), fractions, colors, CycleMethod.NO_CYCLE)); g.fill(new Rectangle2D.Double(x1, y0 - s, s, s)); // Bottom Left g.setPaint(new RadialGradientPaint( new Rectangle2D.Double(x0 - s, y1 - s, s + s, s + s), fractions, colors, CycleMethod.NO_CYCLE)); g.fill(new Rectangle2D.Double(x0 - s, y1, s, s)); // Bottom Right g.setPaint(new RadialGradientPaint( new Rectangle2D.Double(x1 - s, y1 - s, s + s, s + s), fractions, colors, CycleMethod.NO_CYCLE)); g.fill(new Rectangle2D.Double(x1, y1, s, s)); } public static Color getShadowColor() { return shadowColor; } public static void setShadowColor(Color shadowColor) { DropShadowPanel.shadowColor = shadowColor; } public static int getShadowSize() { return shadowSize; } public static void setShadowSize(int shadowSize) { DropShadowPanel.shadowSize = shadowSize; } public static int getShadowDistance() { return shadowDistance; } public static void setShadowDistance(int distance) { DropShadowPanel.shadowDistance = distance; } } 

In Java 6:

Java 6

In Java 7/8:

Java 7/8

    0