List of usage examples for java.awt RenderingHints KEY_ANTIALIASING
Key KEY_ANTIALIASING
To view the source code for java.awt RenderingHints KEY_ANTIALIASING.
Click Source Link
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void handleJpg(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename, JpegOptions options) throws IOException { response.setContentType("image/jpeg"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".jpg\";"); BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData)); Dimension newDimension = calculateDimension(image, width, height); int imgWidth = image.getWidth(); int imgHeight = image.getHeight(); if (newDimension != null) { imgWidth = newDimension.width;/*from w ww.j ava 2s . c o m*/ imgHeight = newDimension.height; } BufferedImage newImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, imgWidth, imgHeight, Color.BLACK, null); g.dispose(); if (newDimension != null) { g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } try (ImageOutputStream ios = ImageIO.createImageOutputStream(response.getOutputStream())) { Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer = iter.next(); ImageWriteParam iwp = writer.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); if (options != null && options.quality != null && options.quality != 0 && options.quality != 100) { iwp.setCompressionQuality(options.quality / 100f); } else { iwp.setCompressionQuality(1); } writer.setOutput(ios); writer.write(null, new IIOImage(newImage, null, null), iwp); writer.dispose(); } }
From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java
public void render(final Graphics2D g) throws IOException { final Object antialiasText = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); final Object antialiasDraw = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Object antialiasAlpha = g.getRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION); try {// w w w . java 2 s . c o m processAntialias(this.quality, g); this.svgGraphicsNode.primitivePaint(g); } finally { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antialiasText == null ? RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT : antialiasText); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasDraw == null ? RenderingHints.VALUE_ANTIALIAS_DEFAULT : antialiasDraw); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, antialiasAlpha == null ? RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT : antialiasAlpha); } }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context/*ww w .j av a2s . c o m*/ * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java
private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) { // log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint); final int fromX = sourcePoint.x; final int fromY = sourcePoint.y; final int toX = sinkPoint.x; final int toY = sinkPoint.y; float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f; f1 = fromX;//from ww w . ja v a 2s.co m f2 = fromY; f3 = fromX; f4 = fromY + WIRE_DIP_PIXELS; f5 = toX; f6 = toY + WIRE_DIP_PIXELS; f7 = toX; f8 = toY; final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); final Rectangle cubicCurveBounds = cubicCurve.getBounds(); final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS; // int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS; int imageHeightToUse = cubicCurveBounds.height; // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip" if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) { imageHeightToUse += (WIRE_DIP_PIXELS / 2); } // bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB ); try { tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource, allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB, imageWidthToUse, imageHeightToUse); bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage(); final Graphics2D g2d = bufferedImage.createGraphics(); g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse); g2d.setComposite(AlphaComposite.SrcOver); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); // Draw the highlight and shadow if (DRAW_HIGHTLIGHT_AND_SHADOW) { final Graphics2D sG2d = (Graphics2D) g2d.create(); sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET); sG2d.setColor(Color.BLUE.darker()); sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); sG2d.draw(offSetCubicCurve); final Graphics2D hG2d = (Graphics2D) g2d.create(); hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET); hG2d.setColor(Color.WHITE); hG2d.setStroke( new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); hG2d.draw(offSetCubicCurve); } g2d.setColor(Color.BLACK); g2d.setStroke(wireStroke); g2d.draw(offSetCubicCurve); g2d.setColor(Color.BLUE); g2d.setStroke(wireBodyStroke); g2d.draw(offSetCubicCurve); // For debugging, draw a green line around the outside of this image. if (DRAW_WIRE_BOUNDING_BOX) { g2d.setStroke(basicStrokeOfOne); g2d.setColor(Color.GREEN); g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1); } rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER; rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER; rectangle.width = imageWidthToUse; rectangle.height = imageHeightToUse; } catch (final Exception e) { final String msg = "Exception caught allocating buffered image: " + e.toString(); log.error(msg, e); } }
From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java
/** * Creates a new demo application./* ww w . j a v a2 s . com*/ * * @param title the frame title. */ public FrequencyDomainRenderer(String title, JPanel panel, String side, String type) { this.side = side; this.type = type; serie.setKey(side); dataset.addSeries(serie); JFreeChart chart = ChartFactory.createXYAreaChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.xlabel"), java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.ylabel2"), dataset, PlotOrientation.VERTICAL, true, true, false); // TextTitle t1 = new TextTitle( "Espectro de Frequncia Estimado (PSD)", new Font("SansSerif", Font.BOLD, 14) ); // //TextTitle t2 = new TextTitle( "valores atualizados a cada potncia de 2", new Font("SansSerif", Font.PLAIN, 11) ); // chart.addSubtitle(t1); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.addSubtitle(t2); plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLUE); plot.setRangeGridlinePaint(Color.CYAN); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); //plot.setRangePannable(true); plot.setForegroundAlpha(0.65f); //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer = plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); } else { renderer.setSeriesPaint(0, Color.RED); } // renderer.setSeriesLinesVisible(0, true); // renderer.setSeriesShapesVisible(0, false); // renderer.setSeriesLinesVisible(1, true); // renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.setForegroundAlpha(0.5f); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); final ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickMarkPaint(Color.black); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); NumberAxis numDomainAxis = (NumberAxis) plot.getDomainAxis(); numDomainAxis.setAutoRangeIncludesZero(true); // // final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)"); // // plot.setRangeAxis(rangeAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickMarkPaint(Color.black); numRangeAxis = (NumberAxis) plot.getRangeAxis(); numRangeAxis.setAutoRangeIncludesZero(true); vlfTarget.setLabel("VLF"); vlfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); vlfTarget.setLabelAnchor(RectangleAnchor.CENTER); vlfTarget.setLabelTextAnchor(TextAnchor.CENTER); vlfTarget.setPaint(new Color(0, 100, 255, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(vlfTarget, Layer.BACKGROUND); lfTarget.setLabel("LF"); lfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); lfTarget.setLabelAnchor(RectangleAnchor.CENTER); lfTarget.setLabelTextAnchor(TextAnchor.CENTER); lfTarget.setPaint(new Color(255, 255, 0, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(lfTarget, Layer.BACKGROUND); hfTarget.setLabel("HF"); hfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); hfTarget.setLabelAnchor(RectangleAnchor.CENTER); hfTarget.setLabelTextAnchor(TextAnchor.CENTER); hfTarget.setPaint(new Color(255, 0, 255, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(hfTarget, Layer.BACKGROUND); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait")); chartPanel = new ChartPanel(chart); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
public void exportPng(File dst) throws IOException { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {/*from ww w.j a va 2 s .c o m*/ final Map hints = new HashMap(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } this.paintComponent(g2); g2.dispose(); if (!dst.getName().endsWith(".png")) dst = new File(dst.getName() + ".png"); ImageIO.write(img, "png", dst); }
From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java
/** * Render the pie chart with the given height * /*from w w w. j a va2 s. c o m*/ * @param height * The height of the resulting image * @return The pie chart rendered as an image */ public BufferedImage render(int height) { BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.scale(zoom, zoom); // fill background to white g2.setColor(Color.WHITE); g2.fill(new Rectangle(totalWidth, totalHeight)); // prepare render hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // draw shadow image g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver()); double start = 0; List<Arc2D> pies = new ArrayList<>(); // pie segmente erzeugen und fuellen if (total == 0) { g2.setColor(BRIGHT_GRAY); g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); g2.setColor(Color.WHITE); g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); } else { for (Segment s : segments) { double portionDegrees = s.getPortion() / total; Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor()); if (withSubSegments) { double smallRadius = radius * s.getSubSegmentRatio(); paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker()); } start += portionDegrees; // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen) String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0); p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25") s.setPercent(p + "%"); pies.add(pie); } // weissen Rahmen um die pie segmente zeichen g2.setColor(Color.WHITE); for (Arc2D pie : pies) { g2.draw(pie); } } // Legende zeichnen renderLegend(g2); // "xx%" Label direkt auf die pie segmente zeichen g2.setColor(Color.WHITE); float fontSize = 32f; g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD)); start = 0; for (Segment s : segments) { if (s.getPortion() < 1E-6) { continue; // ignore segments with portions that are extremely small } double portionDegrees = s.getPortion() / total; double angle = start + portionDegrees / 2; // genau in der Mitte des Segments double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt); int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2); g2.drawString(s.getPercent(), x, y); start += portionDegrees; } return image; }
From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java
/** * Process a GET request.//from w w w. j a va 2s. c om * * @param request the request. * @param response the response. * * @throws ServletException if there is a servlet related problem. * @throws IOException if there is an I/O problem. */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); try { String type = request.getParameter("type"); String format = request.getParameter("format"); String eid = request.getParameter("eid"); JFreeChart chart = null; if ("pie".equalsIgnoreCase(type)) { chart = createPieChart(); } else if ("bar".equalsIgnoreCase(type)) { chart = createBarChart(); } else if ("time".equalsIgnoreCase(type)) { chart = createTimeSeriesChart(); } else if ("exp".equalsIgnoreCase(type)) { chart = createXYChart(eid); } else if ("wall".equalsIgnoreCase(type)) { chart = createWallclockChart(eid); } else { chart = null; } // Render if (chart != null) { if ("svg".equalsIgnoreCase(format)) { response.setContentType("image/svg+xml"); writeChartAsSVG(out, chart, 600, 500); } else { response.setContentType("image/png"); // force aliasing of the rendered content.. chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ChartUtilities.writeChartAsPNG(out, chart, 600, 500); } } } catch (Exception e) { System.err.println(e.toString()); e.printStackTrace(); } finally { out.close(); } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
/** * Sets high-quality rendering hints on the current Graphics2D. *///w w w . ja va 2 s . c o m private void setRenderingHints() { graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
From source file:DrawShapes_2008.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; // Paint a gradient for the sky GradientPaint background = new GradientPaint(0f, 0f, Color.GRAY.darker(), 0f, (float) getHeight(), Color.GRAY.brighter()); g2d.setPaint(background);/*from w w w . j ava 2 s . c o m*/ g2d.fillRect(0, 0, getWidth(), 4 * getHeight() / 5); // Paint a gradient for the ground background = new GradientPaint(0f, (float) 4 * getHeight() / 5, Color.BLACK, 0f, (float) getHeight(), Color.GRAY.darker()); g2d.setPaint(background); g2d.fillRect(0, 4 * getHeight() / 5, getWidth(), getHeight() / 5); // Enable anti-aliasing to get smooth outlines g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Iterate through all of the current shapes for (Shape shape : shapes) { // Get the bounds to compute the RadialGradient properties Rectangle rect = shape.getBounds(); Point2D center = new Point2D.Float(rect.x + (float) rect.width / 2.0f, rect.y + (float) rect.height / 2.0f); float radius = (float) rect.width / 2.0f; float[] dist = { 0.1f, 0.9f }; Color[] colors = { Color.WHITE, Color.BLACK }; // Create and set a RadialGradient centered on the object, // going from white at the center to black at the edges RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); // Finally, render our shape g2d.fill(shape); } }