问题描述
我如何以编程方式使Node
的背景透明-(透明);我目前正在将AnchorPane
作为父节点与其他ProgressIndicator
和其他节点作为子节点一起玩,我希望它们脱颖而出吗?我尝试使用Scene
,它与我想要的不是很接近,有任何解决方法吗?
How do i programmatically make a Node
's background transparent-(see through); I am currently playing with AnchorPane
as a parent Node to other ProgressIndicator
and other nodes as children, and i want them to stand out ? I tried with Scene
and it wasn't close to what i wanted, any workaround?
让我们说
// 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();
我的要求是让我的孩子Nodes
脱颖而出,而没有AnchorPane
的白色背景-(因此AnchorPane需要透明),我该如何实现?
My requirement here is to make my children Nodes
stand out,without the white background of the AnchorPane
-(so AnchorPane needs to be transparent), how do i achieve that?
推荐答案
包括Stage
,Scene
和Layout Containers
在内的所有内容都有其背景色.因此,如果您需要完整的透明背景,则需要为每个背景设置transparent fill
.
Everything including Stage
, Scene
and Layout Containers
have their background color. So if you need a complete transparent background, you need to set transparent fill
to each of these.
用于舞台
primaryStage.initStyle(StageStyle.TRANSPARENT);
对于场景
scene.setFill(Color.TRANSPARENT);
对于容器
container.setBackground(Background.EMPTY);
为您的代码
Scene scene = new Scene(ap,500,500);
scene.setFill(Color.TRANSPARENT);
ap.setBackground(Background.EMPTY);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
这篇关于透明节点背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!