📜  JavaFX 阴影效果

📅  最后修改于: 2020-10-14 01:40:57             🧑  作者: Mango

JavaFX阴影效果

顾名思义,此效果通过复制节点并使其边缘模糊来创建节点的阴影。名为javafx.scene.effect.Shadow的类表示阴影效果。我们只需要实例化此类即可生成适当的阴影效果。

物产

下表描述了该类的属性以及setter方法。

Property Description Setter Methods
blurType This is a blur type property. This represents the algorithm which is used to blur the shadow. setBlurType(BlurType value)
color This is of color type property. It represents the shadow color. setColor(Color value)
height It represents the vertical size of the shadow blur. setHeight(double value)
input It represents the input for this effect. setInput(Effect value)
radius It represents the radius of the shadow. setRadius(double value)
width It represents the horizontal size of the shadow blur. setWidth(double value)

建设者

该类包含三个构造函数。

  • public Shadow():使用默认参数创建一个新实例
  • public Shadow(double radius,Color color):使用指定的半径和颜色创建一个新实例。
  • public Shadow(BlurType blurtype,Color color,double radius):创建一个具有指定半径,颜色和模糊类型的新实例。

例:

package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.Shadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class ShadowExample extends Application{

@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
Image img = new Image("https://www.javatpoint.com/images/logo/jtp_logo.png");
ImageView imgview = new ImageView(img);
imgview.setFitHeight(100);
imgview.setFitWidth(350);
imgview.setX(100);
imgview.setY(100);
Shadow shadow = new Shadow();
shadow.setBlurType(BlurType.GAUSSIAN);
shadow.setColor(Color.BLACK);
shadow.setHeight(30);
shadow.setRadius(12);
shadow.setWidth(20);
imgview.setEffect(shadow);
Group root = new Group();
root.getChildren().add(imgview);
Scene scene = new Scene(root,600,350);
primaryStage.setScene(scene);
primaryStage.setTitle("Shadow Effect Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}

}