Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent Node Background

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?

lets say

// 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();

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?

like image 418
Elltz Avatar asked Mar 12 '15 08:03

Elltz


1 Answers

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.

For Stage

primaryStage.initStyle(StageStyle.TRANSPARENT);

For Scene

scene.setFill(Color.TRANSPARENT);

For Containers

container.setBackground(Background.EMPTY);

For your code

Scene scene = new Scene(ap,500,500);
scene.setFill(Color.TRANSPARENT);
ap.setBackground(Background.EMPTY);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
like image 83
ItachiUchiha Avatar answered Jan 04 '23 03:01

ItachiUchiha