Javafx creating white artifacts appear at the site of the rounding rect I want to create this rect with rounded corners, but for some reason when I try to add a button white artifacts appear when rendering code:
Rectangle rect = new Rectangle(320, 160);
rect.setArcWidth(25);
rect.setArcHeight(25);
StackPane stackPane = new StackPane();
Pane pane = new Pane();
Scene scene = new Scene(pane, Color.TRANSPARENT);
scene.setFill(Color.TRANSPARENT);
primaryStage.initStyle(StageStyle.TRANSPARENT);
Button button = new Button("Button1");
Text text = new Text("SomeText");
text.setFont(font);
stackPane.getChildren().add(text);
stackPane.getChildren().add(asGuest);
pane.getChildren().addAll(rect, stroke);
pane.getChildren().add(stackPane);
primaryStage.show();
I could reproduce your problem; it seems that the Pane
creates it; adding the following line seems to solve it:
// given the imports:
import javafx.geometry.Insets;
import javafx.scene.layout.CornerRadii;
// line:
pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
(as per the comment from Slaw, this can be simplified to pane.setBackground(null)
)