现场演示
->
import java.io.FileNotFoundException; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.effect.InnerShadow; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; public class InnerShadowEffectExample extends Application { public void start(Stage stage) throws FileNotFoundException { //创建一个文本对象 String str = "Nhooo"; Text text = new Text(30.0, 100.0, str); //设置字体 Font font = Font.font("Brush Script MT", FontWeight.BOLD, 110); text.setFont(font); //设置文字颜色 text.setFill(Color.BLUEVIOLET); //创建内部阴影效果 InnerShadow shadow = new InnerShadow(); shadow.setOffsetX(8.0); shadow.setOffsetY(8.0); //将效果设置为文本 text.setEffect(shadow); //设置舞台 Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Inner Shadow Effect"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果