2017-07-13 2 views
0

以下の例では、唯一のテキストのために動作しますが、私はステージにボタンを追加すると、透明は私が探しています何 (のみステージ)

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.VBox; 
import javafx.scene.text.Font; 
import javafx.scene.text.Text; 
import javafx.stage.Stage; 
import javafx.stage.StageStyle; 

public class Main extends Application { 

    @Override 
    public void start(Stage stage) { 
     stage.initStyle(StageStyle.TRANSPARENT); 
     Text text = new Text("!"); 
     text.setFont(new Font(40)); 
     VBox box = new VBox(); 
     Button btn = new Button("Test transparent"); 
     box.getChildren().addAll(text, btn); 
     //if I removed the btn, transparent works as expected. 
     final Scene scene = new Scene(box,300, 250); 
     scene.setFill(null); 
     stage.setScene(scene); 
     stage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

非アクティブになるだけにありますステージを透明にしますが、テキストとボタンを表示してください

答えて

1

あなたの場合はButtonは問題ではありません。デフォルトではVBoxは背景が灰色であるため、Stageは透明ですが、VBoxは透明ではありません。あなたはCSSファイルまたはインラインによりまたはコードから透明な背景を設定する必要があります。

CSS:

.your-vbox { 
    -fx-background-color: transparent; 
} 

をインライン:

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

コード:

box.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY))); 
+0

どうもありがとうございます! ! – Moe

関連する問題