如何在 JavaFX 中为文本添加 LCD(液晶显示器)?
javafx.scene.text.Text 类有一个名为 fontSmoothingType 的属性,该属性指定文本的平滑类型。你可以使用 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 {
//Creating a text object
String str = "Tutorialspoint";
Text text = new Text(30.0, 100.0, str);
//Setting the font
Font font = Font.font("Brush Script MT", FontWeight.BOLD, 110);
text.setFont(font);
//Setting color of the text
text.setFill(Color.BLUEVIOLET);
//Setting the liquid crystal display to the text
text.setFontSmoothingType(FontSmoothingType.LCD);
//Setting the color of the text
text.setFill(Color.BROWN);
//Setting the width and color of the stroke
text.setStrokeWidth(1);
text.setStroke(Color.DARKRED);
//Setting the stage
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);
}
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP