/* * This material may not be reproduced or redistributed in whole * or in part without the express prior written consent of * IntercontinentalExchange, Inc. * * Copyright IntercontinentalExchange, Inc. 2013, All Rights * Reserved. */ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import javafx.application.Application; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.ButtonBuilder; import javafx.scene.control.LabelBuilder; import javafx.scene.layout.BorderPaneBuilder; import javafx.stage.Stage; import javafx.stage.WindowEvent; /** * Steps to reproduce: * 1) Launch the application * 2) Click the spawn window button * 3) Lock the screen (on windows, WindowsKey + L) * 4) Wait about 8 seconds * 5) Unlock the screen. * 6) Observe that the spawned window has opened, but nothing is painted. * 7) Mouse over the spawned window content. * 8) Observe that the window paints correctly. * * @author lperkins */ public class JavaFxScreensaverPaintBug extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) throws Exception { Platform.setImplicitExit(true); final AtomicInteger counter = new AtomicInteger(); stage.setScene(new Scene(BorderPaneBuilder.create() .center(ButtonBuilder.create() .text("Spawn Window") .onAction(new EventHandler() { @Override public void handle(ActionEvent event) { new NewWindowTask(counter.incrementAndGet()).execute(); } }) .build()) .build())); stage.setX(100); stage.setY(100); stage.show(); stage.setOnCloseRequest(new EventHandler() { @Override public void handle(WindowEvent event) { System.exit(0); } }); } private static void spawnNewWindow(int id) { Stage stage = new Stage(); stage.setTitle(String.format("Spawned Window (%s)", Integer.toString(id))); stage.setScene(new Scene(BorderPaneBuilder.create() .center(LabelBuilder.create() .text("JavaFX Label") .style("-fx-background-color: orange; -fx-text-fill: black;") .build()) .build())); stage.setX((id % 10) * 120); stage.setY(200); stage.show(); } private static class NewWindowTask implements Runnable { private static final Executor EXECUTOR = Executors.newCachedThreadPool(); private final int id; private boolean openWindow; public NewWindowTask(int id) { this.id = id; openWindow = false; } public void execute() { EXECUTOR.execute(this); } @Override public void run() { if (openWindow) { System.out.println("---dmarkov before"); spawnNewWindow(id); System.out.println("---dmarkov after"); } else { openWindow = true; try { Thread.sleep(5000L); } catch (InterruptedException e) { // ignored } Platform.runLater(this); } } } // end class NewWindowTask }