小编ahm*_*raf的帖子

透明场景和舞台不适用于 javafx 中的按钮

我正在尝试使用按钮制作透明场景和舞台,但它似乎仅适用于文本。这是我的简单代码

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class TransparentStage extends Application {

@Override
public void start(Stage stage) {
    stage.initStyle(StageStyle.TRANSPARENT);
    Text text = new Text("Transparent!");
    text.setFont(new Font(40));
    //Button button = new Button("btn");
    VBox box = new VBox();
    box.getChildren().add(text);
    //box.getChildren().add(button);
    final Scene scene = new Scene(box,300, 300);
    scene.setFill(Color.TRANSPARENT);
    stage.setScene(scene);
    stage.show();
}

public static void main(String[] args) {
    launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)

结果

但如果我取消注释按钮,结果将在这里

它看起来不再透明,但只是有底漆。那么透明不适用于按钮吗?如果我应该添加一个按钮呢?谢谢 。

java javafx

4
推荐指数
1
解决办法
918
查看次数

标签 统计

java ×1

javafx ×1