import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javax.imageio.ImageIO; public class GrayIcon extends Application { @Override public void start(Stage stage) { Rectangle r = new Rectangle(100, 100, Color.GREEN); Group root = new Group(r); Scene scene = new Scene(root); stage.setScene(scene); stage.getIcons().add(new Image("icon.png")); stage.show(); } static { File f = new File("icon.png"); if (!f.canRead()) { BufferedImage bimg = new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2d = bimg.createGraphics(); g2d.setPaint(new GradientPaint(0, 0, java.awt.Color.WHITE, 32, 32, java.awt.Color.BLACK)); g2d.fillRect(0, 0, 32, 32); try { ImageIO.write(bimg, "png", f); } catch (IOException ex) { Logger.getLogger(GrayIcon.class.getName()).log(Level.SEVERE, null, ex); } } } }