Michael Berry
Michael Berry

Reputation: 72344

Creating a control seems to break transparent stages on JFX8

The above program should create a transparent stage with some text, but the stage appears opaque:

public class Test extends Application { 

@Override 
public void start(Stage primaryStage) { 

    new TextArea(); //Comment this out to enable transparency 

    Stage stage = new Stage(); 
    stage.initStyle(StageStyle.TRANSPARENT); 
    Text text = new Text("Is this transparent?"); 
    VBox box = new VBox(); 
    box.getChildren().add(text); 
    final Scene scene = new Scene(box, 300, 250); 
    scene.setFill(null); 
    stage.setScene(scene); 
    stage.show(); 

} 

} 

The new TextArea() line is what breaks things - comment that out and it all works.

Creating any subclass of control (even via new Control() {};) breaks things - a Region or above does not.

This doesn't occur in Java 7 / JFX2.x.

I've created a JIRA for this since it seems a very obvious regression (https://javafx-jira.kenai.com/browse/RT-38938), but is anyone aware why this happens and thus how to work around it until a fix is provided? I've tried replicating this issue by copying the code in Control's constructor, but this seems to be fine - it's just instantiating Control itself that seems to break things.

Upvotes: 2

Views: 151

Answers (1)

James_D
James_D

Reputation: 209553

I remember some forum discussion on this. I think the general gist is that creating a control forces css to be applied to the layout pane, and the layout pane is getting the opaque background.

As a workaround, make the background of the layout pane transparent:

    box.setStyle("-fx-background-color: transparent;");

Upvotes: 2

Related Questions