如何在 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