该javafx.scene.text.Text类有一个名为财产fontSmoothingType,它指定文本的平滑类型。您可以使用set setFontSmoothingType()方法将值设置为此属性,该方法接受两个参数-
FontSmoothingType.GRAY-这指定默认的灰度平滑。
FontSmoothingType.LCD-这指定LCD平滑度。这利用了LCD显示器的特性,并增强了节点的平滑度。
要将LCD显示添加到文本中-
通过实例化javafx.scene.text.Text类创建一个文本节点。
使用javafx.scene.text.Font类的font()方法之一创建所需的字体。
使用setText()方法将字体设置为文本。
通过将FontSmoothingType.LCD作为参数传递给 setFontSmoothingType()方法,将LCD平滑类型设置为文本。
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class LCDTextExample 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);
//将液晶显示器设置为文本
text.setFontSmoothingType(FontSmoothingType.LCD);
//设置文字的颜色
text.setFill(Color.BROWN);
//设置笔触的宽度和颜色
text.setStrokeWidth(1);
text.setStroke(Color.DARKRED);
//设置舞台
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Liquid Crystal Display");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果