我試圖在Stage按下按鈕時(shí)創(chuàng)建一個(gè)新的。它可以工作,但問題是我希望它Stage是完全透明的,并讓我們看到屏幕后面的內(nèi)容。代碼Dimension Sizescreen = Toolkit.getDefaultToolkit().getScreenSize(); //Main stage with option menu Pane window = new Pane(); Scene scene = new Scene(window); stage.setTitle("Notification Extender"); //Create the button SetLooker Button SetLooker = new Button("Set Looker"); //Add a Event when pressed SetLooker.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { //Create a sub-Stage Pane subwindow = new Pane(); Scene subscene = new Scene(subwindow); Stage substage = new Stage(); substage.setTitle("Notification Extender"); //Set this subStage Transparent substage.initStyle(StageStyle.TRANSPARENT); subscene.setFill(Color.TRANSPARENT); substage.setWidth(Sizescreen.getWidth()); substage.setHeight(Sizescreen.getHeight()); substage.setX(0); substage.setY(0); //Create a a graphique element Rectangle redrec = new Rectangle(120,40,50,50); redrec.setStroke(Color.RED); redrec.setStrokeWidth(2); redrec.setFill(Color.TRANSPARENT); //Add the graphique element to the sub-stage subwindow.getChildren().add(redrec); //Show the sub-stage substage.setScene(subscene); substage.show(); } }); //Add the button to the main stage window.getChildren().add(SetLooker); //Show the main stage stage.setScene(scene); stage.show();問題是,當(dāng)我按下按鈕時(shí),它顯示了舞臺,但它根本不是透明的,而是全白色的。我還嘗試過更改main Stage,但是一旦顯示它就無法更改。
在事件JavaFX上創(chuàng)建新的透明階段
慕碼人8056858
2021-04-17 10:27:51