Ell*_*ltz 4 javafx javafx-2 javafx-8
我如何以编程方式使Node背景透明 - (见下); 我目前正在AnchorPane作为子节点作为父节点播放到ProgressIndicator其他节点和其他节点,我想让它们脱颖而出?我尝试过Scene,它并不接近我想要的,任何解决方法?
我们说吧
// suppose i have a fake layout like this
AnchorPane ap = new AnchorPane();
ProgressIndicator pi = new ProgressIndicator();
ProgressIndicator pii = new ProgressIndicator();
ProgressIndicator piii = new ProgressIndicator();
ProgressIndicator piiii = new ProgressIndicator();
AnchorPane.setRightAnchor(pi, 0.0);
AnchorPane.setBottomAnchor(piii, 0.0);
AnchorPane.setRightAnchor(piiii, 0.0);
AnchorPane.setBottomAnchor(piiii, 0.0);
AnchorPane.setLeftAnchor(piii, 0.0);
Circle circle = new Circle();
circle.setRadius(50);
circle.setFill(Color.RED);
AnchorPane.setBottomAnchor(circle, 210.0);
AnchorPane.setTopAnchor(circle, 210.0);
AnchorPane.setLeftAnchor(circle, 210.0);
AnchorPane.setRightAnchor(circle, 210.0);
ap.getChildren().addAll(pi,pii,piii,circle,piiii);
primaryStage.setScene(new Scene(ap,500,500));
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.show();
Run Code Online (Sandbox Code Playgroud)
我的要求是让我的孩子Nodes脱颖而出,没有白色背景AnchorPane- (所以AnchorPane需要透明),我该如何实现?
Ita*_*iha 10
一切包括Stage,Scene并Layout Containers有背景颜色.因此,如果您需要完整的透明背景,则需要设置其中transparent fill的每一个.
对于舞台
primaryStage.initStyle(StageStyle.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)
对于场景
scene.setFill(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)
对于容器
container.setBackground(Background.EMPTY);
Run Code Online (Sandbox Code Playgroud)
为了你的代码
Scene scene = new Scene(ap,500,500);
scene.setFill(Color.TRANSPARENT);
ap.setBackground(Background.EMPTY);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
Run Code Online (Sandbox Code Playgroud)