FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
OS X 10.11.1
Windows 7
A DESCRIPTION OF THE PROBLEM :
The documentation for GraphicsContext.clearRect states that it uses the current clip. This works as expected if the clip is set to a rectangle. However, if set to a non-rectangular shape using eg GraphicsContext.arc or lineTo to draw any other shape, clearRect has no effect at all.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A blank window is shown.
ACTUAL -
A window with a circle drawn in it is shown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
Canvas canvas = new Canvas(400, 400);
root.getChildren().add(canvas);
GraphicsContext context = canvas.getGraphicsContext2D();
context.beginPath();
context.arc(50, 50, 40, 40, 0, 360);
context.closePath();
context.clip();
context.fillRect(0, 0, 200, 200); //Draws a circle, illustrates clip is set correctly
context.clearRect(0, 0, 200, 200); //Has no effect
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
GraphicsContext.fillRect works as expect using the clip mask. So it is possible to erase in non-rectangular shapes by drawing with the background colour using fillRect. However, fillRect does not working for setting a transparent background so this workaround is not entirely effective.
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
OS X 10.11.1
Windows 7
A DESCRIPTION OF THE PROBLEM :
The documentation for GraphicsContext.clearRect states that it uses the current clip. This works as expected if the clip is set to a rectangle. However, if set to a non-rectangular shape using eg GraphicsContext.arc or lineTo to draw any other shape, clearRect has no effect at all.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A blank window is shown.
ACTUAL -
A window with a circle drawn in it is shown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
Canvas canvas = new Canvas(400, 400);
root.getChildren().add(canvas);
GraphicsContext context = canvas.getGraphicsContext2D();
context.beginPath();
context.arc(50, 50, 40, 40, 0, 360);
context.closePath();
context.clip();
context.fillRect(0, 0, 200, 200); //Draws a circle, illustrates clip is set correctly
context.clearRect(0, 0, 200, 200); //Has no effect
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
GraphicsContext.fillRect works as expect using the clip mask. So it is possible to erase in non-rectangular shapes by drawing with the background colour using fillRect. However, fillRect does not working for setting a transparent background so this workaround is not entirely effective.