Q:

Flash a rectangle in JavaFX

How can I cause a rectangle to flash in and out of view in JavaFX.
I am making a word search game, and I have a 2D array of randomised chars's.
I am printing this array to a 600x600 canvas like so:
for (int i = 0; i < gameBoard.length; i++) {
        for (int j = 0; j < gameBoard[0].length; j++) {
            gc.fillText(String.valueOf(gameBoard[i][j]), (25 + (20 * j)), (25 + (20 * i)));
        }
    }

I also have a square being drawn onto the same canvas at like so:
    gc.setFill(Color.BLACK);
    gc.fillRect((24 + (20 * colSelection)), (14 + (20 * rowSelection)), 15, 15);

meaning I can move the square around by incrementing rowSelection and colSelection. This gives: this.
Now the only issue is that I need the rectangle to flash in, so that the letter underneath is stil visible when selected. How can I do this? I've tried setting the color to opaque but that also causes the rest of the game board to become invisible. Is there a way to do this I cant think of? 
I'm new to JavaFX so any help is appreciated.

A:

Use save() and restore() to change the colors back to the old values or restore the old values by setting the properties to the old values yourself.
The easiest way of adding white text on black background would be to:

set the fill to black
draw the rect
set the fill to white
draw the text

If this is not possible in your case you could draw a white background before drawing the text and use DIFFERENCE as blend mode to draw a white rect on top of the text later which inverts the colors in the rect:
Canvas canvas = new Canvas(400, 400);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
gc.setFill(Color.BLACK);
gc.fillText("Hello world", 30, 30);
gc.save();
gc.setGlobalBlendMode(BlendMode.DIFFERENCE);
gc.setFill(Color.WHITE);
gc.fillRect(10, 10, 100, 100);
gc.restore(); // restore old settings

// some more rendering with old settings
gc.fillRect(100, 100, 100, 100);

