创建一个控件似乎打破了JFX8上的透明阶段 [英] Creating a control seems to break transparent stages on JFX8

查看:135
本文介绍了创建一个控件似乎打破了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(); 

} 

} 

new TextArea() line是什么破坏了东西 - 注释掉它并且一切正常。

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

创建任何控件的子类(甚至通过 new Control(){}; )打破了一些事情 - Region 或更高版本没有。

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

这在Java 7 / JFX2.x中不会发生。

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

我为此创建了一个JIRA,因为它似乎一个非常明显的回归( https://javafx-jira.kenai.com/browse/RT- 38938 ),但有人知道为什么会发生这种情况,从而如何解决它直到提供修复?我试过通过复制 Control 的构造函数中的代码来复制这个问题,但这似乎很好 - 它只是实例化 Control 本身似乎破坏了事情。

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.

推荐答案

记住一些论坛讨论。我认为一般的要点是创建一个控件强制css应用于布局窗格,布局窗格正在获得不透明的背景。

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.

作为一种解决方法,make布局窗格的背景透明:

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

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

这篇关于创建一个控件似乎打破了JFX8上的透明阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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