如何在 JavaFX 中添加删除线和下划线?
在 JavaFX 中,文本节点由 **Javafx.scene.text.Text** 类表示。要在 JavaFx 窗口中插入/显示文本,您需要 -
实例化 Text 类。
使用 setter 方法或将它们作为参数传递给构造函数来设置基本属性(如位置和文本字符串)。
将创建的节点添加到 Group 对象。
**javafx.scene.text.Text** 类的 **删除线** 属性确定文本的每一行是否应该有一条直线穿过它的中间。您可以使用 **setStrikeThrough()** 方法为此属性设置值。它接受布尔值。您可以通过将 true 作为参数传递给此方法来删除文本(节点)。
**javafx.scene.text.Text** 类的 **下划线** 属性确定文本的每一行是否应该在其下方有一条直线。您可以使用 **setUnderline()** 方法为此属性设置值。它接受布尔值。您可以通过将 true 作为参数传递给此方法来在下划线下方添加一行。
示例
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.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class Underline_StrikeThrough 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.DARKCYAN);
//Setting the width and color of the stroke
text.setStrokeWidth(2);
text.setStroke(Color.DARKSLATEGRAY);
//Underlining the text
text.setUnderline(true);
//Striking through the text
text.setStrikethrough(true);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Underline And Strike-through");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出

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