📅  最后修改于: 2020-10-14 01:41:00             🧑  作者: Mango
此效果类似于阴影效果。但是,在DropShadow中,节点的副本将以指定的大小和颜色显示在原始节点的后面。类javafx.scene.effect.DropShadow表示DropShadow效果。我们只需要实例化此类即可产生适当的效果。
下表描述了该类的属性以及setter方法。
Property | Description | Setter Methods |
---|---|---|
blurType | This represents the algorithm used to blur the shadow. | setBlurType(BlurType value) |
setBlurType(BlurType value) | The color of the shadow blur kernel. This property is of color type. | setColor(Color value) |
height | This represents the height of the shadow blur kernel. This property is of double type. | setHeight(Double value) |
input | This represents the input for the effect. | setInput(Effect value) |
offsetX | This represents the X coordinate of the shadow offset. This properly is of double type. | setOffsetX(Double value) |
offsetY | This represents the Y coordinate of the shadow offset. This property is of double type. | setOffsetY(Double value) |
Radius | This represents the radius of the shadow blur kernel. | setRadius(Double value) |
Spread | It represents the spread of the shadow blur kernel. Is is of double type. | setSpread(Double value) |
Width | It represents the width of the shadow blur kernel. | setWidth(double value) |
该类包含四个构造函数
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class DropShadowExample 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.setX(130);
imgview.setY(125);
imgview.setFitWidth(175);
DropShadow drop = new DropShadow();
drop.setBlurType(BlurType.GAUSSIAN);
drop.setColor(Color.BLACK);
drop.setHeight(100);
drop.setWidth(150);
drop.setOffsetX(10);
drop.setOffsetY(10);
drop.setSpread(0.2);
drop.setRadius(10);
imgview.setEffect(drop);
Group root = new Group();
Scene scene = new Scene(root,400,300);
root.getChildren().add(imgview);
primaryStage.setScene(scene);
primaryStage.setTitle("DropShadow Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}