import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polyline;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ShadowTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Polyline polyline1 = new Polyline();
polyline1.setStrokeWidth(13);
polyline1.setStroke(Color.RED);
polyline1.getPoints().addAll(150.,50.);
polyline1.getPoints().addAll(150.,100.);
polyline1.getPoints().addAll(200.,100.);
// 阴影向内
InnerShadow innerShadow = new InnerShadow();
// 颜色蔓延的距离
innerShadow.setRadius(6);
// OffsetX正,则从左至右向内;负,则从右至左向内
innerShadow.setOffsetX(-2);
// OffsetY正,则从上至下向内;负,则从下至上向内
innerShadow.setOffsetY(-2);
innerShadow.setColor(Color.GRAY);
polyline1.setEffect(innerShadow);
Polyline polyline2 = new Polyline();
polyline2.setStrokeWidth(13);
polyline2.setStroke(Color.RED);
polyline2.getPoints().addAll(50.,50.);
polyline2.getPoints().addAll(50.,100.);
polyline2.getPoints().addAll(100.,100.);
// 阴影向外
DropShadow dropShadow = new DropShadow();
// 颜色蔓延的距离
dropShadow.setRadius(8);
// 水平方向,0则向两侧,正则向右,负则向左
dropShadow.setOffsetX(3);
// 竖直方向,0则向两侧,正则向下,负则向上
dropShadow.setOffsetY(3);
// 颜色变淡的程度
dropShadow.setSpread(0.4);
dropShadow.setColor(Color.DARKRED);
polyline2.setEffect(dropShadow);
Pane pane = new Pane(polyline1, polyline2);
primaryStage.setScene(new Scene(pane,400,200));
primaryStage.show();
}
}