package bugs.writableimage; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.image.ImageView; import javafx.scene.image.PixelWriter; import javafx.scene.image.WritableImage; import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.stage.Stage; public class UpdateError extends Application { private final static int size = 5000; private final static int w = size; private final static int h = size; private WritableImage wi; private PixelWriter pw; @Override public void start(Stage stage) { StackPane root = new StackPane(); Scene scene = new Scene(root, 800, 800); ImageView iv = new ImageView(); wi = new WritableImage(w, h); pw = wi.getPixelWriter(); iv.setImage(wi); root.getChildren().add(iv); stage.setTitle(getClass().getSimpleName()); stage.setScene(scene); stage.show(); root.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent e) { Color c = new Color(Math.random(), Math.random(), Math.random(), 1.0); for (int iy = 0; iy < h; ++iy) { for (int ix = 0; ix < w; ++ix) { pw.setColor(ix, iy, c); } } System.out.println("New color set."); } }); } public static void main(String[] args) { launch(args); } }