Creating a control seems to break transparent stages on JFX8

有些话、适合烂在心里 提交于 2019-12-07 21:34:03

问题


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.


回答1:


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;");


来源:https://stackoverflow.com/questions/26278698/creating-a-control-seems-to-break-transparent-stages-on-jfx8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!