透明节点背景 [英] Transparent Node Background

查看:73
本文介绍了透明节点背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何以编程方式使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?

推荐答案

包括StageSceneLayout 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);

这篇关于透明节点背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆