ใน JavaFX โหนดข้อความจะแสดงโดย Javafx.scene.text.Text ระดับ. ในการแทรก/แสดงข้อความในหน้าต่าง JavaFx คุณต้อง -
-
ยกตัวอย่างคลาสข้อความ
-
ตั้งค่าคุณสมบัติพื้นฐาน เช่น ตำแหน่งและสตริงข้อความ โดยใช้เมธอด setter หรือข้ามไปเป็นอาร์กิวเมนต์ของคอนสตรัคเตอร์
-
เพิ่มโหนดที่สร้างขึ้นไปยังวัตถุกลุ่ม
การทะลุทะลวง คุณสมบัติของ javafx.scene.text.Text class กำหนดว่าแต่ละบรรทัดของข้อความควรมีเส้นตรงผ่านตรงกลางหรือไม่ คุณสามารถตั้งค่าคุณสมบัตินี้โดยใช้ setStrikeThrough() กระบวนการ. ยอมรับค่าบูลีน คุณสามารถขีดทับข้อความ (โหนด) โดยส่งค่า true เป็นอาร์กิวเมนต์ของวิธีนี้
ขีดเส้นใต้ คุณสมบัติของ javafx.scene.text.Text class กำหนดว่าแต่ละบรรทัดของข้อความควรมีเส้นตรงด้านล่างหรือไม่ คุณสามารถตั้งค่าคุณสมบัตินี้โดยใช้ 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);
}
} ผลลัพธ์
