setEffect()를 사용하여 JavaFX의 모든 노드 개체에 효과를 추가할 수 있습니다. 방법. 이 메소드는 Effect 개체를 허용합니다. 클래스를 생성하고 현재 노드에 추가합니다.
javafx.scene.effect.GaussianBlur.GaussianBlur 클래스는 내부적으로 가우스 컨볼루션 커널을 사용하는 흐림 효과를 나타냅니다. 따라서 텍스트 노드에 흐림 효과를 추가하려면 -
-
기본 x,y 좌표(위치) 및 텍스트 문자열을 생성자에 대한 인수로 무시하고 Text 클래스를 인스턴스화합니다.
-
글꼴, 획 등과 같은 원하는 속성을 설정합니다.
-
GaussianBlur 를 인스턴스화하여 흐림 효과 만들기 수업.
-
setEffect()를 사용하여 생성된 효과를 텍스트 노드로 설정합니다. 방법.
-
마지막으로 생성된 텍스트 노드를 Group 개체에 추가합니다.
예시
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class TextBlurEffect extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Creating a text object
String str = "Welcome to Tutorialspoint";
Text text = new Text(30.0, 80.0, str);
//Setting the font
Font font = Font.font("Brush Script MT", FontWeight.BOLD,
FontPosture.REGULAR, 65);
text.setFont(font);
//Setting the color of the text
text.setFill(Color.BROWN);
//Setting the width and color of the stroke
text.setStrokeWidth(2);
text.setStroke(Color.BLUE);
//Setting the blur effect to the text
GaussianBlur blur = new GaussianBlur();
text.setEffect(blur);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Blur Effect");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} 출력
