📜  JavaFX 镜像效果

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

JavaFX反射效果

通常,反射可以定义为方向的变化。 JavaFX允许我们在任何节点上生成反射效果。反射效果基本上将节点的反射添加到其底部。它由类javafx.scene.effect.Reflection表示。我们只需要实例化此类即可将适当的效果应用于节点。

物产

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

Property Description Setter Methods
bottomOpacity It is a double type property. It represents the opacity of the reflection at the bottom extreme. setBottomOpacity(double value)
fraction It is a double type property. It represents the fraction of the input that is to be displayed in the reflection. setFraction(double value)
input It is a object type property. It represents the input for the effect. setInput(Effect value)
topOffset It is a double type property. It represents the distance between the top and bottom of the reflection. setTopOffset(Double value)
topOpacity It represents the opacity of the reflection at the top of the input. setTopOpacity(Double value)

建设者

该类包含两个构造函数。

  • public Reflection():使用默认参数创建一个Reflection的新实例
  • public Reflection(double topOffset,double fraction,double topOpacity,double bottomOpacity):使用指定的参数创建一个Reflection的新实例

例:

package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Reflection;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ReflectionExample extends Application{

@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
Text text = new Text();
text.setFont(Font.font("calibri",FontWeight.BLACK,FontPosture.REGULAR,20));
text.setText("Welcome to JavaTPoint");
text.setX(90);
text.setY(90);
Reflection ref = new Reflection();
ref.setBottomOpacity(0.2);
ref.setFraction(12);
ref.setTopOffset(10);
ref.setTopOpacity(0.2);
text.setEffect(ref);
Group root = new Group();
Scene scene = new Scene(root,400,300);
root.getChildren().add(text);
primaryStage.setScene(scene);
primaryStage.setTitle("Reflection Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}