Drop-shadow in an undecorated Pane

前端 未结 4 1980
时光说笑
时光说笑 2020-12-06 07:15

I\'m trying to make my Pane a little bit better, visually, so, what I\'m doing is: set my stage UNDECORATED (OK) and (TRYING) to add a drop-shadow effect (NOT OK).

I\

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 07:51

    Simple working example.

    Here is fxml structure:

    AnchorPane(200,200) // pane for space for shadow
        \- AnchorPane(center) // appliction pane
             \- Label // application content
    

    Real screen.fxml:

    
       
          
             
                
             
                
             
          
       
    
    

    Main.java

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/sample/screen.fxml"));
        AnchorPane shadowPane = loader.load();
        AnchorPane rootPane = (AnchorPane) shadowPane.lookup("#rootPane");
        rootPane.setStyle("-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.4), 10, 0.5, 0.0, 0.0);" +
                          "-fx-background-color: white;"); // Shadow effect
    
        Scene scene = new Scene(shadowPane);
        stage.setScene(scene);
    
        shadowPane.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, null, null))); // Some borders for for clarity
    
        shadowPane.setStyle("-fx-background-color: transparent;"); // Makes shadowPane transparent
        scene.setFill(Color.TRANSPARENT); // Fill our scene with nothing
        stage.initStyle(StageStyle.TRANSPARENT); // Important one!
        stage.show();
    }
    

提交回复
热议问题